public function actionDefault() { $this->template->schema = $this->schema; if ($this->userEntity->id === 1) { $this->template->blocks = $this->orm->blocks->findAll()->orderBy('id', 'ASC'); } else { $this->template->blocks = $this->orm->blocks->findAllButOldWeb()->orderBy('id', 'ASC'); } $this->template->getBlock = function ($id) { return $this->orm->blocks->getById($id); }; /** @var TextInput[]|EditorSelector[] $form */ $form = $this['schemaForm-form']; if ($this->schema) { $form['title']->setDefaultValue($this->schema->title); $form['description']->setDefaultValue($this->schema->description); $form['editors']->setEditable($this->schema->author->id === $this->userEntity->id || $this->user->isAllowed($this->schema->subject)); $form['editors']->setDefaultValue($this->schema->editors->get()->fetchAll()); $form['editors']->setEntity($this->schema); $layout = $this->schema->layout; unset($layout[1]); // remove spacer columns unset($layout[3]); $this->template->layout = $layout; } else { $this->template->layout = $this->schemaLayout->getDefaultLayout(); $form['editors']->setEditable(TRUE); } }
public function renderDefault() { $this->template->schema = $this->schema; $this->template->layout = $this->schemaLayout->trim($this->schema->layout); $this->template->getBlock = function ($id) { if (!$this->preloadedBlocks) { $b = iterator_to_array($this->schema->blocks); foreach ($b as $block) { $this->preloadedBlocks[$block->id] = $block; } } return isset($this->preloadedBlocks[$id]) ? $this->preloadedBlocks[$id] : $this->orm->blocks->getById($id); }; $this->template->continueTo = NULL; if (!$this->user->isEphemeralGuest()) { $this->template->continueTo = $this->getContinueToContent(); } }
protected function process() { $v = $this->getValues(); $parsed = Json::decode($v->layout); $parsed = $this->schemaLayout->normalize($parsed); $schema = $this->presenter->schema; $mode = 'edited'; if (!$schema) { $schema = new Rme\Schema(); $this->orm->schemas->attach($schema); $schema->author = $this->presenter->userEntity; $schema->blockSchemaBridges = []; $mode = 'added'; } /** @var self|EditorSelector[] $this */ if ($this['editors']->isEditable()) { $schema->editors = $v->editors; } $schema->title = $v->title; $schema->description = $v->description; $schema->layout = $parsed; foreach ($schema->blocks as $block) { $block->dependencies = []; } foreach ($this->schemaLayout->buildBlockDependencies($parsed) as $blockId => $deps) { /** @var Rme\Block $block */ $block = $this->orm->blocks->getById($blockId); $block->dependencies = $deps; } $this->orm->flush(); $this->presenter->purgeCacheTag('header'); $this->presenter->purgeCacheTag("schema-{$schema->id}"); $producer = $this->queue->getProducer('updateSchema'); $producer->publish(serialize(['schema' => new EntityPointer($schema)])); $this->presenter->flashSuccess("editor.{$mode}.schema"); $this->presenter->redirect('this', ['schemaId' => $schema->id]); }