/** * 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 */ public 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); 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; }
public function getEditForm($id = null, $fields = null) { $record = $this->getRecord($id ? $id : $this->currentModuleID()); return parent::getEditForm($record, $record ? $record->getSettingsFields() : null); }