Example #1
0
 public function update($id)
 {
     $filename = get('filename');
     $page = $this->page($id);
     if (!$page) {
         return response::error(l('files.error.missing.page'));
     }
     $file = $page->file($filename);
     if (!$file) {
         return response::error(l('files.error.missing.file'));
     }
     $blueprint = blueprint::find($page);
     $fields = $blueprint->files()->fields($page);
     // trigger the validation
     $form = new Form($fields->toArray());
     $form->validate();
     // fetch the form data
     $data = filedata::createByInput($file, $form->serialize());
     // stop at invalid fields
     if (!$form->isValid()) {
         return response::error(l('files.show.error.form'), 400, array('fields' => $form->fields()->filterBy('error', true)->pluck('name')));
     }
     try {
         $file->update($data, app::$language);
         return response::success('success', array('data' => $data));
     } catch (Exception $e) {
         return response::error($e->getMessage());
     }
 }
Example #2
0
 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);
 }
Example #4
0
 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());
     }
 }