示例#1
0
 public function formfield($id)
 {
     $path = func_get_args();
     $style = $this->container['styles']->get($id);
     // Load blueprints.
     $blueprints = new BlueprintsForm($style);
     list($fields, $path, $value) = $blueprints->resolve(array_slice($path, 1), '/');
     if (!$fields) {
         throw new \RuntimeException('Page Not Found', 404);
     }
     $fields['is_current'] = true;
     // Get the prefix.
     $prefix = "styles.{$id}." . implode('.', $path);
     if ($value !== null) {
         $parent = $fields;
         $fields = ['fields' => $fields['fields']];
         $prefix .= '.' . $value;
     }
     array_pop($path);
     $this->params = ['blueprints' => $fields, 'data' => $this->container['config']->get($prefix), 'parent' => $path ? "configurations/{$this->params['configuration']}/styles/blocks/{$id}/" . implode('/', $path) : "configurations/{$this->params['configuration']}/styles/blocks/{$id}", 'route' => 'styles.' . $prefix] + $this->params;
     if (isset($parent['key'])) {
         $this->params['key'] = $parent['key'];
     }
     return $this->container['admin.theme']->render('@gantry-admin/pages/configurations/styles/field.html.twig', $this->params);
 }
示例#2
0
 public function formfield($id)
 {
     $path = func_get_args();
     $end = end($path);
     if ($end === '') {
         array_pop($path);
     }
     if (end($path) == 'validate') {
         return call_user_func_array([$this, 'validate'], $path);
     }
     $particle = $this->container['particles']->get($id);
     // Load blueprints.
     $blueprints = new BlueprintsForm($particle);
     list($fields, $path, $value) = $blueprints->resolve(array_slice($path, 1), '/');
     if (!$fields) {
         throw new \RuntimeException('Page Not Found', 404);
     }
     $data = $this->request->post->getJsonArray('data');
     $offset = "particles.{$id}." . implode('.', $path);
     if ($value !== null) {
         $parent = $fields;
         $fields = ['fields' => $fields['fields']];
         $offset .= '.' . $value;
         $data = $data ?: $this->container['config']->get($offset);
         $data = ['data' => $data];
         $scope = 'data.';
     } else {
         $data = $data ?: $this->container['config']->get($offset);
         $scope = 'data';
     }
     $fields['is_current'] = true;
     array_pop($path);
     $configuration = "configurations/{$this->params['configuration']}";
     $this->params = ['configuration' => $configuration, 'blueprints' => $fields, 'data' => $data, 'prefix' => '', 'scope' => $scope, 'parent' => $path ? "{$configuration}/settings/particles/{$id}/" . implode('/', $path) : "{$configuration}/settings/particles/{$id}", 'route' => "configurations.{$this->params['configuration']}.settings.{$offset}"] + $this->params;
     if (isset($parent['key'])) {
         $this->params['key'] = $parent['key'];
     }
     if (isset($parent['value'])) {
         $this->params['title'] = $parent['value'];
     }
     return $this->container['admin.theme']->render('@gantry-admin/pages/configurations/settings/field.html.twig', $this->params);
 }
示例#3
0
文件: Menu.php 项目: nmsde/gantry5
 public function particle()
 {
     $data = $this->request->post['item'];
     if ($data) {
         $data = json_decode($data, true);
     } else {
         $data = $this->request->post->getArray();
     }
     $name = isset($data['particle']) ? $data['particle'] : null;
     $file = CompiledYamlFile::instance("gantry-admin://blueprints/menu/block.yaml");
     $block = new BlueprintsForm($file->content());
     $blueprints = new BlueprintsForm($this->container['particles']->get($name));
     $file->free();
     // Load particle blueprints and default settings.
     $validator = $this->loadBlueprints('menu');
     $callable = function () use($validator) {
         return $validator;
     };
     // Create configuration from the defaults.
     $item = new Config($data, $callable);
     $item->def('type', 'particle');
     $item->def('title', $blueprints->get('name'));
     $item->def('options.type', $blueprints->get('type', 'particle'));
     $item->def('options.particle', []);
     $item->def('options.block', []);
     $this->params += ['item' => $item, 'block' => $block, 'data' => ['particles' => [$name => $item->options['particle']]], 'particle' => $blueprints, 'parent' => 'settings', 'prefix' => "particles.{$name}.", 'route' => "configurations.default.settings", 'action' => "menu/particle/{$name}"];
     return $this->container['admin.theme']->render('@gantry-admin/pages/menu/particle.html.twig', $this->params);
 }
示例#4
0
 /**
  * Validate data for the atom.
  *
  * @param string $name
  * @return JsonResponse
  */
 public function atomValidate($name)
 {
     // Load particle blueprints and default settings.
     $validator = new Blueprints();
     $validator->embed('options', $this->container['particles']->get($name));
     $blueprints = new BlueprintsForm($this->container['particles']->get($name));
     // Create configuration from the defaults.
     $data = new Config([], function () use($validator) {
         return $validator;
     });
     $data->set('type', $name);
     $data->set('title', $this->request->post['title'] ?: $blueprints->get('name'));
     $data->set('attributes', $this->request->post->getArray("particles.{$name}"));
     $data->def('attributes.enabled', 1);
     $block = $this->request->post->getArray('block');
     foreach ($block as $key => $param) {
         if ($param === '') {
             unset($block[$key]);
         }
     }
     if ($block) {
         $data->join('options.block', $block);
     }
     // TODO: validate
     // Fill parameters to be passed to the template file.
     $this->params['item'] = (object) $data->toArray();
     return new JsonResponse(['item' => $data->toArray()]);
 }
示例#5
0
 public function validateParticle($name)
 {
     // Validate only exists for JSON.
     if (empty($this->params['ajax'])) {
         $this->undefined();
     }
     /** @var Request $request */
     $request = $this->container['request'];
     // Load particle blueprints and default settings.
     $validator = new Blueprints();
     $validator->embed('options', $this->container['particles']->get($name));
     $blueprints = new BlueprintsForm($this->container['particles']->get($name));
     // Create configuration from the defaults.
     $data = new Config([], function () use($validator) {
         return $validator;
     });
     $data->set('type', 'particle');
     $data->set('particle', $name);
     $data->set('title', $request->get('title') ?: $blueprints->get('name'));
     $data->set('options.particle', $request->getArray("particles.{$name}"));
     $data->def('options.particle.enabled', 1);
     $block = $request->getArray('block');
     foreach ($block as $key => $param) {
         if ($param === '') {
             unset($block[$key]);
         }
     }
     $data->join('options.block', $block);
     // TODO: validate
     // Fill parameters to be passed to the template file.
     $this->params['item'] = (object) $data->toArray();
     $html = $this->container['admin.theme']->render('@gantry-admin/menu/item.html.twig', $this->params);
     return new JsonResponse(['item' => $data->toArray(), 'html' => $html]);
 }