public function update($id = '') { $page = $this->page($id); if (!$page) { return response::error(l('pages.error.missing')); } $blueprint = blueprint::find($page); $fields = $blueprint->fields($page); $oldTitle = (string) $page->title(); // trigger the validation $form = new Form($fields->toArray()); $form->validate(); // fetch the data for the form $data = pagedata::createByInput($page, $form->serialize()); // stop at invalid fields if (!$form->isValid()) { return response::error(l('pages.show.error.form'), 400, array('fields' => $form->fields()->filterBy('error', true)->pluck('name'))); } try { $page->update($data); // make sure that the sorting number is correct if ($page->isVisible()) { $num = api::createPageNum($page); if ($num !== $page->num()) { if ($num > 0) { $page->sort($num); } } } history::visit($page->id()); return response::success('success', array('file' => $page->content()->root(), 'data' => $data, 'uid' => $page->uid(), 'uri' => $page->id())); } catch (Exception $e) { return response::error($e->getMessage()); } }
public static function keep($page) { $blueprint = blueprint::find($page); $fields = $blueprint->fields($page); // trigger the validation $form = new Form($fields->toArray()); // fetch the data for the form $data = pagedata::createByInput($page, $form->serialize()); static::update($page, $data); }
public function update($id = '') { $page = $this->page($id); if (!$page) { return response::error(l('pages.error.missing')); } $blueprint = blueprint::find($page); $fields = $blueprint->fields($page); $oldTitle = (string) $page->title(); // trigger the validation $form = new Form($fields->toArray()); $form->validate(); // fetch the data for the form $data = pagedata::createByInput($page, $form->serialize()); // stop at invalid fields if (!$form->isValid()) { return response::error(l('pages.show.error.form'), 400, array('fields' => $form->fields()->filterBy('error', true)->pluck('name'))); } try { PageStore::discard($page); $page->update($data); // make sure that the sorting number is correct if ($page->isVisible()) { $num = api::createPageNum($page); if ($num !== $page->num()) { if ($num > 0) { $page->sort($num); } } } // get the blueprint of the parent page to find the // correct sorting mode for this page $parentBlueprint = blueprint::find($page->parent()); // auto-update the uid if the sorting mode is set to zero if ($parentBlueprint->pages()->num()->mode() == 'zero') { $uid = str::slug($page->title()); $page->move($uid); } history::visit($page->id()); kirby()->trigger('panel.page.update', $page); return response::success('success', array('file' => $page->content()->root(), 'data' => $data, 'uid' => $page->uid(), 'uri' => $page->id())); } catch (Exception $e) { return response::error($e->getMessage()); } }
public static function createPage($uri, $title, $template, $uid) { $parent = empty($uri) ? site() : page($uri); $uid = empty($uid) ? str::slug($title) : str::slug($uid); if (empty($title)) { throw new Exception(l('pages.add.error.title')); } if (empty($template)) { throw new Exception(l('pages.add.error.template')); } $data = pagedata::createByBlueprint($template, array('title' => $title)); $page = $parent->children()->create($uid, $template, $data); $blueprint = blueprint::find($page); if (is_array($blueprint->pages()->build())) { foreach ($blueprint->pages()->build() as $build) { $missing = a::missing($build, array('title', 'template', 'uid')); if (!empty($missing)) { continue; } static::createPage($page->uri(), $build['title'], $build['template'], $build['uid']); } } return $page; }