/** * @return Form */ public function getEditForm($id = null, $fields = null) { $siteConfig = SiteConfig::current_site_config(); $fields = $siteConfig->getCMSFields(); // Tell the CMS what URL the preview should show $fields->push(new HiddenField('PreviewURL', 'Preview URL', RootURLController::get_homepage_link())); // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load $fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator())); $navField->setAllowHTML(true); $actions = $siteConfig->getCMSActions(); $form = CMSForm::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-content center cms-edit-form'); // don't add data-pjax-fragment=CurrentForm, its added in the content template instead if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); } $form->setHTMLID('Form_EditForm'); $form->loadDataFrom($siteConfig); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // Use <button> to allow full jQuery UI styling $actions = $actions->dataFields(); if ($actions) { foreach ($actions as $action) { $action->setUseButtonTag(true); } } $this->extend('updateEditForm', $form); return $form; }
/** * Additional magic happens here. Trick LeftAndMain into thinking we're a previewable SiteTree object. * * @return Form */ public function ItemEditForm() { Requirements::javascript(MODULATOR_PATH . '/javascript/LeftAndMain.Preview.js'); $form = parent::ItemEditForm(); $record = $this->getRecord(); // Hide the 'Save & publish' button if we're on a brand new module. if ($record && $record->ID == 0) { $actions = $form->Actions(); // Remove the publish button on the pre-module state $actions->removeByName('action_publish'); // Remove the save action if there are no sub-classes to instantiate $classes = ClassInfo::subclassesFor('PageModule'); unset($classes['PageModule']); if (!count($classes)) { $actions->removeByName('action_save'); } } // Enable CMS preview // .cms-previewable enables the preview panel in the front-end // .cms-pagemodule CSS class is used by our javascript to handle previews if ($form && is_object($form)) { $form->addExtraClass('cms-previewable cms-pagemodule'); } // Creat a navigaor and point it at the parent page $navigator = new SilverStripeNavigator($this->record->Page()); $navField = new LiteralField('SilverStripeNavigator', $navigator->renderWith('LeftAndMain_SilverStripeNavigator')); $navField->setAllowHTML(true); $fields = $form->Fields(); $fields->push($navField); return $form; }
private function injectNavigatorAndPreview(&$form, &$fields) { $editForm = $fields->fieldByName('EditForm'); //TODO: Do we need to verify we are in the right controller? $template = Controller::curr()->getTemplatesWithSuffix('_SilverStripeNavigator'); $navigator = new SilverStripeNavigator($this->owner->record); $field = new LiteralField('SilverStripeNavigator', $navigator->renderWith($template)); $field->setAllowHTML(true); $fields->push($field); $form->addExtraClass('cms-previewable'); $form->addExtraClass(' cms-previewabledataobject'); $form->removeExtraClass('cms-panel-padded center'); }
public function ItemEditForm() { $form = parent::ItemEditForm(); // Do these action update only when the current record is_a newsletter if ($this->record && $this->record instanceof Newsletter) { $form->setActions($this->updateCMSActions($form->Actions())); $form->Fields()->push(new HiddenField("PreviewURL", "PreviewURL", $this->LinkPreview())); // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load $navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()); $navField->setAllowHTML(true); $form->Fields()->push($navField); } return $form; }
/** * @param null $id Not used. * @param null $fields Not used. * @return Form */ public function getEditForm($id = null, $fields = null) { $objectClass = $this->config()->get('tree_class'); $object = $objectClass::get()->first(); if (!$object || !$object->exists()) { $currentStage = Versioned::current_stage(); Versioned::reading_stage('Stage'); $object = $objectClass::create(); $object->write(); if ($objectClass::has_extension('Versioned')) { $object->doPublish(); } Versioned::reading_stage($currentStage); } $fields = $object->getCMSFields(); $fields->push(HiddenField::create('ID', 'ID', $object->ID)); $fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator())); $navField->setAllowHTML(true); $actions = new FieldList(); $actions->push(FormAction::create('doSave', 'Save')->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')); $form = CMSForm::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-content center cms-edit-form'); if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); } $form->setHTMLID('Form_EditForm'); $form->loadDataFrom($object); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // Use <button> to allow full jQuery UI styling $actions = $actions->dataFields(); if ($actions) { foreach ($actions as $action) { $action->setUseButtonTag(true); } } $this->extend('updateEditForm', $form); return $form; }
/** * @param null $id Not used. * @param null $fields Not used. * * @return Form */ public function getEditForm($id = null, $fields = null) { $siteConfig = SiteConfig::current_site_config(); $fields = $siteConfig->getCMSFields(); // Tell the CMS what URL the preview should show $home = Director::absoluteBaseURL(); $fields->push(new HiddenField('PreviewURL', 'Preview URL', $home)); // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load $fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator())); $navField->setAllowHTML(true); // Retrieve validator, if one has been setup (e.g. via data extensions). if ($siteConfig->hasMethod("getCMSValidator")) { $validator = $siteConfig->getCMSValidator(); } else { $validator = null; } $actions = $siteConfig->getCMSActions(); $form = CMSForm::create($this, 'EditForm', $fields, $actions, $validator)->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-content center cms-edit-form'); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); } $form->setHTMLID('Form_EditForm'); $form->loadDataFrom($siteConfig); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // Use <button> to allow full jQuery UI styling $actions = $actions->dataFields(); if ($actions) { foreach ($actions as $action) { $action->setUseButtonTag(true); } } $this->extend('updateEditForm', $form); return $form; }
/** * Calls {@link SiteTree->getCMSFields()} * * @param Int $id * @param FieldList $fields * @return Form */ public function getEditForm($id = null, $fields = null) { if (!$id) { $id = $this->currentPageID(); } if (is_object($id)) { $record = $id; } else { $record = $this->getRecord($id); if ($record && !$record->canView()) { return Security::permissionFailure($this); } } if ($record) { $fields = $fields ? $fields : $record->getCMSFields(); if ($fields == null) { user_error("getCMSFields() returned null - it should return a FieldList object. \n\t\t\t\t\tPerhaps you forgot to put a return statement at the end of your method?", E_USER_ERROR); } // Add hidden fields which are required for saving the record // and loading the UI state if (!$fields->dataFieldByName('ClassName')) { $fields->push(new HiddenField('ClassName')); } if (Object::has_extension($this->stat('tree_class'), 'Hierarchy') && !$fields->dataFieldByName('ParentID')) { $fields->push(new HiddenField('ParentID')); } // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load if (in_array('CMSPreviewable', class_implements($record))) { $navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()); $navField->setAllowHTML(true); $fields->push($navField); } if ($record->hasMethod('getAllCMSActions')) { $actions = $record->getAllCMSActions(); } else { $actions = $record->getCMSActions(); // add default actions if none are defined if (!$actions || !$actions->Count()) { if ($record->hasMethod('canEdit') && $record->canEdit()) { $actions->push(FormAction::create('save', _t('CMSMain.SAVE', 'Save'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')); } if ($record->hasMethod('canDelete') && $record->canDelete()) { $actions->push(FormAction::create('delete', _t('ModelAdmin.DELETE', 'Delete'))->addExtraClass('ss-ui-action-destructive')); } } } // Use <button> to allow full jQuery UI styling $actionsFlattened = $actions->dataFields(); if ($actionsFlattened) { foreach ($actionsFlattened as $action) { $action->setUseButtonTag(true); } } $form = new Form($this, "EditForm", $fields, $actions); $form->addExtraClass('cms-edit-form'); $form->loadDataFrom($record); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); // Set this if you want to split up tabs into a separate header row // if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); // Add a default or custom validator. // @todo Currently the default Validator.js implementation // adds javascript to the document body, meaning it won't // be included properly if the associated fields are loaded // through ajax. This means only serverside validation // will kick in for pages+validation loaded through ajax. // This will be solved by using less obtrusive javascript validation // in the future, see http://open.silverstripe.com/ticket/2915 and // http://open.silverstripe.com/ticket/3386 if ($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); // The clientside (mainly LeftAndMain*.js) rely on ajax responses // which can be evaluated as javascript, hence we need // to override any global changes to the validation handler. $form->setValidator($validator); } else { $form->unsetValidator(); } if ($record->hasMethod('canEdit') && !$record->canEdit()) { $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); } } else { $form = $this->EmptyForm(); } return $form; }
/** * @param Int $id * @param FieldList $fields * @return Form */ public function getEditForm($id = null, $fields = null) { if (!$id) { $id = $this->currentPageID(); } $form = parent::getEditForm($id); // TODO Duplicate record fetching (see parent implementation) $record = $this->getRecord($id); if ($record && !$record->canView()) { return Security::permissionFailure($this); } if (!$fields) { $fields = $form->Fields(); } $actions = $form->Actions(); if ($record) { $deletedFromStage = $record->IsDeletedFromStage; $deleteFromLive = !$record->ExistsOnLive; $fields->push($idField = new HiddenField("ID", false, $id)); // Necessary for different subsites $fields->push($liveLinkField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink())); $fields->push($liveLinkField = new HiddenField("LiveLink")); $fields->push($stageLinkField = new HiddenField("StageLink")); $fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle)); if ($record->ID && is_numeric($record->ID)) { $liveLink = $record->getAbsoluteLiveLink(); if ($liveLink) { $liveLinkField->setValue($liveLink); } if (!$deletedFromStage) { $stageLink = Controller::join_links($record->AbsoluteLink(), '?stage=Stage'); if ($stageLink) { $stageLinkField->setValue($stageLink); } } } // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load if (in_array('CMSPreviewable', class_implements($record)) && !$fields->fieldByName('SilverStripeNavigator')) { $navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()); $navField->setAllowHTML(true); $fields->push($navField); } // getAllCMSActions can be used to completely redefine the action list if ($record->hasMethod('getAllCMSActions')) { $actions = $record->getAllCMSActions(); } else { $actions = $record->getCMSActions(); // Find and remove action menus that have no actions. if ($actions && $actions->Count()) { $tabset = $actions->fieldByName('ActionMenus'); if ($tabset) { foreach ($tabset->getChildren() as $tab) { if (!$tab->getChildren()->count()) { $tabset->removeByName($tab->getName()); } } } } } // Use <button> to allow full jQuery UI styling $actionsFlattened = $actions->dataFields(); if ($actionsFlattened) { foreach ($actionsFlattened as $action) { $action->setUseButtonTag(true); } } if ($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); } else { $validator = new RequiredFields(); } $form = CMSForm::create($this, "EditForm", $fields, $actions, $validator)->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->loadDataFrom($record); $form->disableDefaultAction(); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('center ' . $this->BaseCSSClasses()); // if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); // Set validation exemptions for specific actions $form->setValidationExemptActions(array('restore', 'revert', 'deletefromlive', 'rollback')); // Announce the capability so the frontend can decide whether to allow preview or not. if (in_array('CMSPreviewable', class_implements($record))) { $form->addExtraClass('cms-previewable'); } if (!$record->canEdit() || $deletedFromStage) { $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); } $this->extend('updateEditForm', $form); return $form; } else { if ($id) { $form = CMSForm::create($this, "EditForm", new FieldList(new LabelField('PageDoesntExistLabel', _t('CMSMain.PAGENOTEXISTS', "This page doesn't exist"))), new FieldList())->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); 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; }
/** * @param Int $id * @param FieldList $fields * @return Form */ public function getEditForm($id = null, $fields = null) { if(!$id) $id = $this->currentPageID(); $form = parent::getEditForm($id); // TODO Duplicate record fetching (see parent implementation) $record = $this->getRecord($id); if($record && !$record->canView()) return Security::permissionFailure($this); if(!$fields) $fields = $form->Fields(); $actions = $form->Actions(); if($record) { $deletedFromStage = $record->IsDeletedFromStage; $deleteFromLive = !$record->ExistsOnLive; $fields->push($idField = new HiddenField("ID", false, $id)); // Necessary for different subsites $fields->push($liveURLField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink())); $fields->push($liveURLField = new HiddenField("LiveURLSegment")); $fields->push($stageURLField = new HiddenField("StageURLSegment")); $fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle)); $fields->push(new HiddenField('Sort','', $record->Sort)); if($record->ID && is_numeric( $record->ID ) ) { $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".\"ID\" = $record->ID"); if($liveRecord) $liveURLField->setValue($liveRecord->AbsoluteLink()); } if(!$deletedFromStage) { $stageURLField->setValue(Controller::join_links($record->AbsoluteLink(), '?stage=Stage')); } // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load if(in_array('CMSPreviewable', class_implements($record)) && !$fields->fieldByName('SilverStripeNavigator')) { $navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()); $navField->setAllowHTML(true); $fields->push($navField); } // getAllCMSActions can be used to completely redefine the action list if($record->hasMethod('getAllCMSActions')) { $actions = $record->getAllCMSActions(); } else { $actions = $record->getCMSActions(); } // Use <button> to allow full jQuery UI styling $actionsFlattened = $actions->dataFields(); if($actionsFlattened) foreach($actionsFlattened as $action) $action->setUseButtonTag(true); if($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); } else { $validator = new RequiredFields(); } $form = new Form($this, "EditForm", $fields, $actions, $validator); $form->loadDataFrom($record); $stageURLField->setValue(Controller::join_links($record->getStageURLSegment(), '?stage=Stage')); $form->disableDefaultAction(); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('center ss-tabset ' . $this->BaseCSSClasses()); // if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); if(!$record->canEdit() || $deletedFromStage) { $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); } $this->extend('updateEditForm', $form); return $form; } else if($id) { return new Form($this, "EditForm", new FieldList( new LabelField('PageDoesntExistLabel',_t('CMSMain.PAGENOTEXISTS',"This page doesn't exist"))), new FieldList() ); } }
/** * @param null $id Not used. * @param null $fields Not used. * @return Form */ public function getEditForm($id = null, $fields = null) { $page = $this->findOrMakePage(); $fields = $page->getCMSFields(); $fields->push(new HiddenField('PreviewURL', 'Preview URL', RootURLController::get_homepage_link())); $fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator())); $navField->setAllowHTML(true); $currentStage = Versioned::current_stage(); Versioned::reading_stage('Stage'); $form = CMSForm::create($this, 'EditForm', $fields, $this->getCMSActions())->setHTMLID('Form_EditForm'); if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); } $form->setResponseNegotiator($this->getResponseNegotiator())->addExtraClass('cms-content center cms-edit-form')->setHTMLID('Form_EditForm')->loadDataFrom($page)->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $this->extend('updateEditForm', $form); Versioned::reading_stage($currentStage); return $form; }