Example #1
0
 public function postSave()
 {
     $input = $this->request->input();
     if (isset($input['template'])) {
         unset($input['template']);
     }
     $chunk = ChunkFacade::create($this->page, $input);
     if ($this->request->input('template')) {
         $chunk->template($this->request->input('template'));
     }
     // This is usually defined by the page controller.
     // We need to define a variant of it incase the callback is used in teh chunk view.
     View::share('chunk', function ($type, $slotname, $page = null) {
         return ChunkFacade::get($type, $slotname, $page);
     });
     View::share('page', $this->page);
     Event::fire(new ChunkWasCreated($this->page, $chunk));
     return ['status' => $this->page->getCurrentVersion()->getStatus(), 'html' => $chunk->render()];
 }
Example #2
0
 public function load(Page $page, $chunks)
 {
     foreach ($chunks as $type => $slotnames) {
         $model = ucfirst($type);
         $class = "\\BoomCMS\\Core\\Chunk\\" . $model;
         $models = $this->find($type, $slotnames, $page->getCurrentVersion());
         $found = [];
         foreach ($models as $m) {
             if ($m) {
                 $found[] = $m->slotname;
                 $chunks[$type][$m->slotname] = new $class($page, $m->toArray(), $m->slotname, $this->allowedToEdit($page));
             }
         }
         $not_found = array_diff($slotnames, $found);
         foreach ($not_found as $slotname) {
             $chunks[$type][$slotname] = new $class($page, [], $slotname, $this->allowedToEdit($page));
         }
     }
     return $chunks;
 }
Example #3
0
 public function get($type, $slotname, Page $page)
 {
     $className = $this->getClassName($type);
     $chunk = $this->find($type, $slotname, $page->getCurrentVersion());
     $attrs = $chunk ? $chunk->toArray() : [];
     return new $className($page, $attrs, $slotname);
 }