function getEditForm($id = null, $fields = null)
 {
     $record = $this->getRecord($id ? $id : $this->currentPageID());
     $form = parent::getEditForm($record, $record ? $record->getCMSFields() : null);
     // TODO Replace with preview button
     $form->Fields()->addFieldToTab('Root.Main', new LiteralField('SwitchView', sprintf('<div class="cms-switch-view field"><label>Preview:</label><div class="middleColumn">%s</div></div>', $this->SwitchView())));
     return $form;
 }
 /**
  * Returns the read only version of the edit form. Detaches all {@link FormAction} 
  * instances attached since only action relates to revert.
  *
  * Permission checking is done at the {@link CMSMain::getEditForm()} level.
  * 
  * @param int $id ID of the record to show
  * @param array $fields optional
  * @param int $versionID
  * @param int $compare Compare mode
  *
  * @return Form
  */
 function getEditForm($id = null, $fields = null, $versionID = null, $compareID = null)
 {
     if (!$id) {
         $id = $this->currentPageID();
     }
     $record = $this->getRecord($id, $versionID);
     $versionID = $record ? $record->Version : $versionID;
     $form = parent::getEditForm($record, $record ? $record->getCMSFields() : null);
     // Respect permission failures from parent implementation
     if (!$form instanceof Form) {
         return $form;
     }
     $nav = new SilverStripeNavigatorItem_ArchiveLink($record);
     $form->setActions(new FieldList($revert = FormAction::create('doRollback', _t('CMSPageHistoryController.REVERTTOTHISVERSION', 'Revert to this version'))->setUseButtonTag(true), $navField = new LiteralField('ArchivedLink', $nav->getHTML())));
     $fields = $form->Fields();
     $fields->removeByName("Status");
     $fields->push(new HiddenField("ID"));
     $fields->push(new HiddenField("Version"));
     $fields = $fields->makeReadonly();
     $navField->setAllowHTML(true);
     foreach ($fields->dataFields() as $field) {
         $field->dontEscape = true;
         $field->reserveNL = true;
     }
     if ($compareID) {
         $link = Controller::join_links($this->Link('show'), $id);
         $view = _t('CMSPageHistoryController.VIEW', "view");
         $message = _t('CMSPageHistoryController.COMPARINGVERSION', "Comparing versions {version1} and {version2}.", array('version1' => sprintf('%s (<a href="%s">%s</a>)', $versionID, Controller::join_links($link, $versionID), $view), 'version2' => sprintf('%s (<a href="%s">%s</a>)', $compareID, Controller::join_links($link, $compareID), $view)));
         $revert->setReadonly(true);
     } else {
         $message = _t('CMSPageHistoryController.VIEWINGVERSION', "Currently viewing version {version}.", array('version' => $versionID));
     }
     $fields->addFieldToTab('Root.Main', new LiteralField('CurrentlyViewingMessage', $this->customise(array('Content' => $message, 'Classes' => 'notice'))->renderWith(array('CMSMain_notice'))), "Title");
     $form->setFields($fields->makeReadonly());
     $form->loadDataFrom(array("ID" => $id, "Version" => $versionID));
     if ($record && $record->isLatestVersion()) {
         $revert->setReadonly(true);
     }
     $form->removeExtraClass('cms-content');
     return $form;
 }
 function getEditForm($id = null, $fields = null)
 {
     $record = $this->getRecord($id ? $id : $this->currentPageID());
     return parent::getEditForm($record, $record ? $record->getSettingsFields() : null);
 }
Esempio n. 4
0
 function testSavePageInCMS()
 {
     $adminUser = $this->objFromFixture('Member', 'admin');
     $enPage = $this->objFromFixture('Page', 'testpage_en');
     $group = new Group();
     $group->Title = 'Example Group';
     $group->write();
     $frPage = $enPage->createTranslation('fr_FR');
     $frPage->write();
     $adminUser->logIn();
     $cmsMain = new CMSMain();
     $origLocale = Translatable::get_current_locale();
     Translatable::set_current_locale('fr_FR');
     $form = $cmsMain->getEditForm($frPage->ID);
     $form->loadDataFrom(array('Title' => 'Translated', 'ViewerGroups' => $group->ID));
     $form->saveInto($frPage);
     $frPage->write();
     $this->assertEquals('Translated', $frPage->Title);
     $this->assertEquals(array($group->ID), $frPage->ViewerGroups()->column('ID'));
     $adminUser->logOut();
     Translatable::set_current_locale($origLocale);
 }
Esempio n. 5
0
 /**
  * Testing retrieval and type of CMS edit form.
  */
 public function testGetEditForm()
 {
     // Login is required prior to accessing a CMS form.
     $this->loginWithPermission('ADMIN');
     // Get a associated with a fixture page.
     $page = $this->objFromFixture('Page', 'page1');
     $controller = new CMSMain();
     $form = $controller->getEditForm($page->ID);
     $this->assertInstanceOf("CMSForm", $form);
     // Ensure that the form will not "validate" on delete or "unpublish" actions.
     $exemptActions = $form->getValidationExemptActions();
     $this->assertContains("delete", $exemptActions);
     $this->assertContains("unpublish", $exemptActions);
 }
 /**
  * Get the fields
  * 
  * @param  Int $id
  * @param  FieldList $fields
  * @return FieldList
  */
 public function getEditForm($id = null, $fields = null)
 {
     $record = $this->getRecord($id ? $id : $this->currentPageID());
     return parent::getEditForm($record, $record ? $record->getBlockBuilderFields() : null);
 }