예제 #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)]);
 }
예제 #2
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()]);
 }
예제 #3
0
파일: Menu.php 프로젝트: nmsde/gantry5
 public function validate($id)
 {
     // Validate only exists for JSON.
     if (empty($this->params['ajax'])) {
         $this->undefined();
     }
     // Load particle blueprints and default settings.
     $validator = $this->loadBlueprints('menu');
     $callable = function () use($validator) {
         return $validator;
     };
     // Create configuration from the defaults.
     $data = new Config($this->request->post->getArray(), $callable);
     // TODO: validate
     return new JsonResponse(['settings' => (array) $data->get('settings')]);
 }
예제 #4
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)]);
 }