Beispiel #1
0
 public function editAction()
 {
     $form = new SitePageForm($this->getServiceLocator());
     $readResponse = $this->api()->read('sites', ['slug' => $this->params('site-slug')]);
     $site = $readResponse->getContent();
     $siteId = $site->id();
     $this->layout()->setVariable('site', $site);
     $readResponse = $this->api()->read('site_pages', ['slug' => $this->params('page-slug'), 'site' => $siteId]);
     $page = $readResponse->getContent();
     $id = $page->id();
     $data = $page->jsonSerialize();
     $form->setData($data);
     if ($this->getRequest()->isPost()) {
         $post = $this->params()->fromPost();
         $form->setData($post);
         if ($form->isValid()) {
             $response = $this->api()->update('site_pages', $id, $post);
             if ($response->isError()) {
                 $form->setMessages($response->getErrors());
             } else {
                 $this->messenger()->addSuccess('Page updated.');
                 // Explicitly re-read the site URL instead of using
                 // refresh() so we catch updates to the slug
                 return $this->redirect()->toUrl($page->url());
             }
         } else {
             $this->messenger()->addError('There was an error during validation');
         }
     }
     $view = new ViewModel();
     $view->setVariable('site', $site);
     $view->setVariable('page', $page);
     $view->setVariable('form', $form);
     $view->setVariable('confirmForm', new ConfirmForm($this->getServiceLocator(), null, ['button_value' => $this->translate('Confirm Delete')]));
     return $view;
 }
Beispiel #2
0
 public function addPageAction()
 {
     $form = new SitePageForm($this->getServiceLocator());
     $readResponse = $this->api()->read('sites', ['slug' => $this->params('site-slug')]);
     $site = $readResponse->getContent();
     $this->layout()->setVariable('site', $site);
     $id = $site->id();
     if ($this->getRequest()->isPost()) {
         $form->setData($this->params()->fromPost());
         if ($form->isValid()) {
             $formData = $form->getData();
             $formData['o:site']['o:id'] = $id;
             $response = $this->api()->create('site_pages', $formData);
             if ($response->isError()) {
                 $form->setMessages($response->getErrors());
             } else {
                 $this->messenger()->addSuccess('Page created.');
                 return $this->redirect()->toRoute('admin/site/page', ['action' => 'index'], true);
             }
         } else {
             $this->messenger()->addError('There was an error during validation');
         }
     }
     $view = new ViewModel();
     $view->setVariable('site', $site);
     $view->setVariable('form', $form);
     return $view;
 }