Exemplo n.º 1
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()]);
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
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]);
 }