public function __construct(array $serialized = null, Grav $grav = null)
 {
     parent::__construct($serialized);
     $this->grav = $grav ?: Grav::instance();
 }
Пример #2
0
 public function validateParticle($name)
 {
     // Validate only exists for JSON.
     if (empty($this->params['ajax'])) {
         $this->undefined();
     }
     // 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', $this->request->post['title'] ?: $blueprints->post['name']);
     $data->set('options.particle', $this->request->post->getArray("particles.{$name}"));
     $data->def('options.particle.enabled', 1);
     $block = $this->request->post->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]);
 }
Пример #3
0
 public function validate($particle)
 {
     // Validate only exists for JSON.
     if (empty($this->params['ajax'])) {
         $this->undefined();
     }
     // Load particle blueprints and default settings.
     $validator = new Blueprints();
     $name = $particle;
     if (in_array($particle, ['wrapper', 'section', 'container', 'grid', 'offcanvas'])) {
         $type = $particle;
         $particle = null;
         $file = CompiledYamlFile::instance("gantry-admin://blueprints/layout/{$type}.yaml");
         $validator->embed('options', $file->content());
         $file->free();
         $defaults = [];
     } else {
         $type = in_array($particle, ['spacer', 'system', 'position']) ? $particle : 'particle';
         $validator->embed('options', $this->container['particles']->get($particle));
         $defaults = (array) $this->container['config']->get("particles.{$particle}");
     }
     // Create configuration from the defaults.
     $data = new Config(['type' => $type], function () use($validator) {
         return $validator;
     });
     // Join POST data.
     $data->join('options', $this->request->post->getArray("particles." . $name));
     if ($particle) {
         $data->set('options.enabled', (int) $data->get('options.enabled', 1));
     }
     if ($particle) {
         if ($type != $particle) {
             $data->set('subtype', $particle);
         }
         $data->join('title', $this->request->post['title'] ?: ucfirst($particle));
     }
     $block = $this->request->post->getArray('block');
     if ($block) {
         // TODO: remove empty items in some other way:
         foreach ($block as $key => $param) {
             if ($param === '') {
                 unset($block[$key]);
                 continue;
             }
             if ($key == 'size') {
                 $param = round($param, 4);
                 if ($param < 5) {
                     $param = 5;
                 } elseif ($param > 100) {
                     $param = 100;
                 }
                 $block[$key] = $param;
             }
         }
         $data->join('block', $block);
     }
     // TODO: validate
     return new JsonResponse(['data' => $data->toArray()]);
 }
Пример #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
 /**
  * Get extra items which haven't been defined in blueprints.
  *
  * @return array
  */
 public function extra()
 {
     return $this->blueprints ? $this->blueprints->extra($this->items) : array();
 }