Exemplo n.º 1
0
 public function validate($group, $id)
 {
     $path = implode('.', array_slice(func_get_args(), 1, -2));
     // Validate only exists for JSON.
     if (empty($this->params['ajax'])) {
         $this->undefined();
     }
     // Load blueprints.
     $validator = $this->container['content']->get("{$group}/{$id}");
     // Create configuration from the defaults.
     $data = new Config([], function () use($validator) {
         return $validator;
     });
     $data->join($path, $this->request->post->getArray('data'));
     // TODO: validate
     return new JsonResponse(['data' => $data->get($path)]);
 }
Exemplo n.º 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]);
 }
Exemplo n.º 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()]);
 }
Exemplo n.º 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()]);
 }
Exemplo n.º 5
0
 public function validate($particle)
 {
     $path = implode('.', array_slice(func_get_args(), 1, -1));
     // Validate only exists for JSON.
     if (empty($this->params['ajax'])) {
         $this->undefined();
     }
     // Load particle blueprints.
     $validator = $this->container['particles']->get($particle);
     // Create configuration from the defaults.
     $data = new Config([], function () use($validator) {
         return $validator;
     });
     /** @var Request $request */
     $request = $this->container['request'];
     $data->join($path, $request->getArray('data'));
     // TODO: validate
     return new JsonResponse(['data' => $data->get($path)]);
 }