/** * @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(); $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; }
/** * Builds the form for creating mock children. * * @return CMSForm */ public function MockChildrenForm() { $pageTypes = array(); $parentID = $this->request->param('ID') ?: $this->request->requestVar('ID'); $parentPage = SiteTree::get()->byID((int) $parentID); if (!$parentPage) { return false; } $allowed_children = $parentPage->allowedChildren(); foreach ($this->PageTypes() as $type) { if (!empty($allowed_children) && !in_array($type->getField('ClassName'), $allowed_children)) { continue; } $html = sprintf('<span class="page-icon class-%s"></span><strong class="title">%s</strong><span class="description">%s</span>', $type->getField('ClassName'), $type->getField('AddAction'), $type->getField('Description')); $pageTypes[$type->getField('ClassName')] = $html; } // Ensure generic page type shows on top if (isset($pageTypes['Page'])) { $pageTitle = $pageTypes['Page']; $pageTypes = array_merge(array('Page' => $pageTitle), $pageTypes); } $numericLabelTmpl = '<span class="step-label"><span class="flyout">%d</span><span class="arrow"></span><span class="title">%s</span></span>'; $keys = array_keys($pageTypes); $fields = new FieldList($typeField = new OptionsetField("PageType", sprintf($numericLabelTmpl, 1, _t('MockData.CHOOSEPAGETYPE', 'Choose the type of page to create')), $pageTypes, reset($keys)), new LiteralField('optionsheader', sprintf($numericLabelTmpl, 2, _t('MockData.CHOOSEOPTIONS', 'Choose options'))), new NumericField('Count', _t('MockData.HOWMANYPAGES', 'How many pages do you want to create?'), 10), new DropdownField('IncludeRelations', _t('MockData.RELATEDDATA', 'Related data'), array(0 => _t('MockData.CREATEMOCKRELATED', 'Create mock data for relations'), 1 => _t('MockData.NATIVEONLY', 'Only populate native fields'))), new DropdownField('DownloadImages', _t('MockData.FILESANDIMAGES', 'Files and Images'), array(0 => _t('MockData.USEEXISTING', 'Use existing files and images'), 1 => _t('MockData.DOWNLOADNEW', 'Download new files and images'))), new HiddenField('ID', '', $parentPage->ID)); $actions = new FieldList(FormAction::create("doAddMockChildren", _t('CMSMain.Create', "Create"))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true)); $form = CMSForm::create($this, "MockChildrenForm", $fields, $actions)->setHTMLID('Form_MockChildrenForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass(' stacked cms-content center cms-edit-form ' . $this->BaseCSSClasses()); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); return $form; }
/** * @return Form * @todo what template is used here? AssetAdmin_UploadContent.ss doesn't seem to be used anymore */ public function getEditForm($id = null, $fields = null) { Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js'); Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css'); $folder = $this->currentPage(); $uploadField = UploadField::create('AssetUploadField', ''); $uploadField->setConfig('previewMaxWidth', 40); $uploadField->setConfig('previewMaxHeight', 30); $uploadField->setConfig('changeDetection', false); $uploadField->addExtraClass('ss-assetuploadfield'); $uploadField->removeExtraClass('ss-uploadfield'); $uploadField->setTemplate('AssetUploadField'); if ($folder->exists() && $folder->getFilename()) { // The Upload class expects a folder relative *within* assets/ $path = preg_replace('/^' . ASSETS_DIR . '\\//', '', $folder->getFilename()); $uploadField->setFolderName($path); } else { $uploadField->setFolderName('/'); // root of the assets } $exts = $uploadField->getValidator()->getAllowedExtensions(); asort($exts); $uploadField->Extensions = implode(', ', $exts); $form = CMSForm::create($this, 'EditForm', new FieldList($uploadField, new HiddenField('ID')), new FieldList())->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses()); // Don't use AssetAdmin_EditForm, as it assumes a different panel structure $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->Fields()->push(new LiteralField('BackLink', sprintf('<a href="%s" class="backlink ss-ui-button cms-panel-link" data-icon="back">%s</a>', Controller::join_links(singleton('AssetAdmin')->Link('show'), $folder ? $folder->ID : 0), _t('AssetAdmin.BackToFolder', 'Back to folder')))); $form->loadDataFrom($folder); return $form; }
/** * @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; }
/** * Gets the form used for agreeing or disagreeing to the ip agreement * @param {int} $id ID of the record to fetch * @param {FieldList} $fields Fields to use * @return {Form} Form to be used */ public function getEditForm($id = null, $fields = null) { $defaultPanel = Config::inst()->get('AdminRootController', 'default_panel'); if ($defaultPanel == 'CodeBank') { $defaultPanel = 'SecurityAdmin'; $sng = singleton($defaultPanel); } $fields = new FieldList(new TabSet('Root', new Tab('Main', new HeaderField('IPMessageTitle', _t('CodeBank.IP_MESSAGE_TITLE', '_You must agree to the following terms before using Code Bank'), 2), new LiteralField('IPMessage', '<div class="ipMessage"><div class="middleColumn">' . CodeBankConfig::CurrentConfig()->dbObject('IPMessage')->forTemplate() . '</div></div>'), new HiddenField('RedirectLink', 'RedirectLink', $sng->Link())))); if (Session::get('CodeBankIPAgreed') === true) { $fields->addFieldToTab('Root.Main', new HiddenField('AgreementAgreed', 'AgreementAgreed', Session::get('CodeBankIPAgreed'))); } $actions = new FieldList(FormAction::create('doDisagree', _t('CodeBankIPAgreement.DISAGREE', '_Disagree'))->addExtraClass('ss-ui-action-destructive'), FormAction::create('doAgree', _t('CodeBankIPAgreement.AGREE', '_Agree'))->addExtraClass('ss-ui-action-constructive')); $form = CMSForm::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm'); $form->disableDefaultAction(); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->addExtraClass('center ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); //Display message telling user to run dev/build because the version numbers are out of sync if (CB_VERSION != '@@VERSION@@' && CodeBankConfig::CurrentConfig()->Version != CB_VERSION . ' ' . CB_BUILD_DATE) { $form->setMessage(_t('CodeBank.UPDATE_NEEDED', '_A database upgrade is required please run {startlink}dev/build{endlink}.', array('startlink' => '<a href="dev/build?flush=all">', 'endlink' => '</a>')), 'error'); } else { if ($this->hasOldTables()) { $form->setMessage(_t('CodeBank.MIGRATION_AVAILABLE', '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.', array('startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">', 'endlink' => '</a>')), 'warning'); } } $form->Actions()->push(new LiteralField('CodeBankVersion', '<p class="codeBankVersion">Code Bank: ' . $this->getVersion() . '</p>')); Requirements::javascript(CB_DIR . '/javascript/CodeBank.IPMessage.js'); return $form; }
/** * @return Form */ public function getEditForm($id = null, $fields = null) { $config = CodeBankConfig::CurrentConfig(); $fields = $config->getCMSFields(); $actions = new FieldList(FormAction::create('doSave', _t('CodeBank.SAVE', '_Save'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'), FormAction::create('doExportToClient', _t('CodeBank.EXPORT_TO_CLIENT', '_Export To Desktop Client'))->setAttribute('data-exporturl', Director::absoluteURL('code-bank-api/export-to-client'))->setAttribute('data-icon', 'export')); if (Permission::check('ADMIN')) { $actions->push(FormAction::create('doImportFromClient', _t('CodeBank.IMPORT_FROM_CLIENT', '_Import From Desktop Client'))->setAttribute('data-icon', 'import')->setAttribute('data-importurl', $this->Link('import-from-client'))); } $form = CMSForm::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm'); $form->addExtraClass('root-form'); $form->addExtraClass('cms-edit-form center'); // don't add data-pjax-fragment=CurrentForm, its added in the content template instead $form->setHTMLID('Form_EditForm'); $form->loadDataFrom($config); $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); //Display message telling user to run dev/build because the version numbers are out of sync if (CB_VERSION != '@@VERSION@@' && CodeBankConfig::CurrentConfig()->Version != CB_VERSION . ' ' . CB_BUILD_DATE) { $form->setMessage(_t('CodeBank.UPDATE_NEEDED', '_A database upgrade is required please run {startlink}dev/build{endlink}.', array('startlink' => '<a href="dev/build?flush=all">', 'endlink' => '</a>')), 'error'); } else { if ($this->hasOldTables()) { $form->setMessage(_t('CodeBank.MIGRATION_AVAILABLE', '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.', array('startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">', 'endlink' => '</a>')), 'warning'); } } $form->Actions()->push(new LiteralField('CodeBankVersion', '<p class="codeBankVersion">Code Bank: ' . $this->getVersion() . '</p>')); return $form; }
public function getEditForm($id = null, $fields = null) { $tabs = new TabSet('Root', new Tab('Main')); $fields = new FieldList($tabs); $caches = array(); $all_caches = SimpleCache::$cache_configs; foreach ($all_caches as $name => $cacheInfo) { $cache = $this->getCache($name); if ($cache) { $stats = $cache->stats(); $fields->addFieldToTab('Root.Info', new HeaderField($name . 'header', $name)); $fields->addFieldToTab('Root.Info', new ReadonlyField($name . 'Hits', 'Hits', $stats->hits)); $fields->addFieldToTab('Root.Info', new ReadonlyField($name . 'Miss', 'Miss', $stats->misses)); $fields->addFieldToTab('Root.Info', new ReadonlyField($name . 'Count', 'Count', $stats->count)); $caches[$name] = $name; } } if (count($caches)) { $fields->addFieldToTab('Root.Main', new CheckboxSetField('ToClear', 'Caches to clear', $caches)); $fields->addFieldToTab('Root.Main', new TextField('Key', 'Key to clear from selected caches')); } $actions = new FieldList(FormAction::create('clear', 'Clear')->setUseButtonTag(true)); $form = CMSForm::create($this, "EditForm", $fields, $actions)->setHTMLID('Form_EditForm'); $form->addExtraClass('cms-edit-form center'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->setTemplate('SimpleCacheAdmin_EditForm'); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); return $form; }
/** * Generates the form used for adding snippets * @return {Form} Form used to add snippets */ public function AddForm() { $sng = singleton('Snippet'); $fields = $sng->getCMSFields(); $validator = $sng->getCMSValidator(); $actions = new FieldList(FormAction::create('doAdd', _t('CodeBank.CREATE', '_Create'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true)); $form = CMSForm::create($this, 'AddForm', $fields, $actions)->setHTMLID('Form_AddForm'); $form->setValidator($validator); $form->disableDefaultAction(); $form->addExtraClass('cms-add-form cms-edit-form'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->addExtraClass('center ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); //Handle Language id in url if ($this->request->getVar('LanguageID')) { $langField = $form->Fields()->dataFieldByName('LanguageID'); if ($langField && $langField->Value() == '') { $langField->setValue(intval(str_replace('language-', '', $this->request->getVar('LanguageID')))); } } //Handle folder id in url (or post) if ($this->request->getVar('FolderID')) { $folder = SnippetFolder::get()->byID(intval($this->request->getVar('FolderID'))); if (!empty($folder) && $folder !== false && $folder->ID != 0) { $langField = $form->Fields()->dataFieldByName('LanguageID')->setValue($folder->ParentID); $form->Fields()->replaceField('LanguageID', $langField->performReadonlyTransformation()); $form->Fields()->push(new HiddenField('FolderID', 'FolderID', $folder->ID)); } } else { if ($this->request->postVar('FolderID')) { $folder = SnippetFolder::get()->byID(intval($this->request->postVar('FolderID'))); if (!empty($folder) && $folder !== false && $folder->ID != 0) { $langField = $form->Fields()->dataFieldByName('LanguageID')->setValue($folder->ParentID); $form->Fields()->replaceField('LanguageID', $langField->performReadonlyTransformation()); $form->Fields()->push(new HiddenField('FolderID', 'FolderID', $folder->ID)); } } } $this->extend('updateAddForm', $form); //Display message telling user to run dev/build because the version numbers are out of sync if (CB_VERSION != '@@VERSION@@' && CodeBankConfig::CurrentConfig()->Version != CB_VERSION . ' ' . CB_BUILD_DATE) { $form->insertBefore(new LiteralField('<p class="message error">' . _t('CodeBank.UPDATE_NEEDED', '_A database upgrade is required please run {startlink}dev/build{endlink}.', array('startlink' => '<a href="dev/build?flush=all">', 'endlink' => '</a>')) . '</p>'), 'LanguageID'); } else { if ($this->hasOldTables()) { $form->insertBefore(new LiteralField('<p class="message warning">' . _t('CodeBank.MIGRATION_AVAILABLE', '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.', array('startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">', 'endlink' => '</a>')) . '</p>'), 'LanguageID'); } } $form->Actions()->push(new LiteralField('CodeBankVersion', '<p class="codeBankVersion">Code Bank: ' . $this->getVersion() . '</p>')); Requirements::javascript(CB_DIR . '/javascript/CodeBank.EditForm.js'); return $form; }
/** * * @param int $id * @param FieldList $fields * @return Form */ public function getEditForm($id = null, $fields = null) { $fields = new FieldList(); $notifications = TimelineEvent::get_all(Member::currentUser()); $gridField = new GridField('TimelineEvents', 'Timeline', $notifications, new TimelineConfig()); $fields->add($gridField); $form = CMSForm::create($this, "EditForm", $fields, new FieldList())->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); return $form; }
protected function buildForm(FieldList $fields, FieldList $actions) { $form = CMSForm::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // Tab nav in CMS is rendered through separate template if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); } $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); return $form; }
public function getEditForm($id = null, $fields = null) { $list = $this->getList(); $listField = GridField::create($this->sanitiseClassName($this->modelClass), false, $list, $fieldConfig = GridFieldConfig_RecordEditor::create($this->stat('page_length'))->removeComponentsByType('GridFieldFilterHeader')->removeComponentsByType('GridFieldDetailForm')->removeComponentsByType('GridFieldDeleteAction')->addComponents(new ExternalDataGridFieldDetailForm())->addComponents(new ExternalDataGridFieldDeleteAction())); // Validation if (singleton($this->modelClass)->hasMethod('getCMSValidator')) { $detailValidator = singleton($this->modelClass)->getCMSValidator(); $listField->getConfig()->getComponentByType('GridFieldDetailForm')->setValidator($detailValidator); } $form = CMSForm::create($this, 'EditForm', new FieldList($listField), new FieldList())->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-edit-form cms-panel-padded center'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $editFormAction = Controller::join_links($this->Link($this->sanitiseClassName($this->modelClass)), 'EditForm'); $form->setFormAction($editFormAction); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $this->extend('updateEditForm', $form); return $form; }
/** * @inheritdoc */ public function getEditForm($id = null, $fields = null) { $model = singleton($this->modelClass); if ($model->has_extension('CatalogPageExtension') || $model->has_extension('CatalogDataObjectExtension')) { $list = $this->getList()->setDataQueryParam(array('Versioned.stage' => 'Stage')); $listField = GridField::create($this->sanitiseClassName($this->modelClass), false, $list, $fieldConfig = GridFieldConfig_RecordEditor::create($this->stat('page_length'))->removeComponentsByType('GridFieldFilterHeader')->removeComponentsByType('GridFieldDeleteAction')->addComponent(new GridfieldPagePublishAction())); $form = CMSForm::create($this, 'EditForm', new FieldList($listField), new FieldList())->setHTMLID('Form_EditForm'); // Validation if (singleton($this->modelClass)->hasMethod('getCMSValidator')) { $detailValidator = singleton($this->modelClass)->getCMSValidator(); $listField->getConfig()->getComponentByType('GridFieldDetailForm')->setValidator($detailValidator); } if ($gridField = $listField->getConfig()->getComponentByType('GridFieldDetailForm')) { $gridField->setItemRequestClass('CatalogPageGridFieldDetailForm_ItemRequest'); } $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-edit-form cms-panel-padded center'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $editFormAction = Controller::join_links($this->Link($this->sanitiseClassName($this->modelClass)), 'EditForm'); $form->setFormAction($editFormAction); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); /** add sorting if we have a field for... */ if (class_exists('GridFieldSortableRows') && ($sortField = $model->getSortFieldname())) { $fieldConfig->addComponent(new GridFieldSortableRows($sortField)); } } else { if (method_exists($model, 'getAdminListField')) { $form = CMSForm::create($this, 'EditForm', new FieldList($model->getAdminListField()), new FieldList(FormAction::create('doSave', 'Save')))->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-edit-form cms-panel-padded center'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $editFormAction = Controller::join_links($this->Link($this->sanitiseClassName($this->modelClass)), 'EditForm'); $form->setFormAction($editFormAction); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); } else { $form = parent::getEditForm(); } } $this->extend('updateEditForm', $form); return $form; }
/** * @return Form */ public function AddForm() { $pageTypes = array(); foreach ($this->PageTypes() as $type) { $html = sprintf('<span class="page-icon class-%s"></span><strong class="title">%s</strong><span class="description">%s</span>', $type->getField('ClassName'), $type->getField('AddAction'), $type->getField('Description')); $pageTypes[$type->getField('ClassName')] = DBField::create_field('HTMLText', $html); } // Ensure generic page type shows on top if (isset($pageTypes['Page'])) { $pageTitle = $pageTypes['Page']; $pageTypes = array_merge(array('Page' => $pageTitle), $pageTypes); } $numericLabelTmpl = '<span class="step-label"><span class="flyout">%d</span><span class="arrow"></span><span class="title">%s</span></span>'; $topTitle = _t('CMSPageAddController.ParentMode_top', 'Top level'); $childTitle = _t('CMSPageAddController.ParentMode_child', 'Under another page'); $fields = new FieldList(new LiteralField('PageModeHeader', sprintf($numericLabelTmpl, 1, _t('CMSMain.ChoosePageParentMode', 'Choose where to create this page'))), $parentModeField = new SelectionGroup("ParentModeField", array(new SelectionGroup_Item("top", null, $topTitle), new SelectionGroup_Item('child', $parentField = new TreeDropdownField("ParentID", "", 'SiteTree', 'ID', 'TreeTitle'), $childTitle))), $typeField = new OptionsetField("PageType", sprintf($numericLabelTmpl, 2, _t('CMSMain.ChoosePageType', 'Choose page type')), $pageTypes, 'Page'), new LiteralField('RestrictedNote', sprintf('<p class="message notice message-restricted">%s</p>', _t('CMSMain.AddPageRestriction', 'Note: Some page types are not allowed for this selection')))); $parentField->setSearchFunction(function ($sourceObject, $labelField, $search) { return DataObject::get($sourceObject, sprintf("\"MenuTitle\" LIKE '%%%s%%' OR \"Title\" LIKE '%%%s%%'", Convert::raw2sql($search), Convert::raw2sql($search))); }); // TODO Re-enable search once it allows for HTML title display, // see http://open.silverstripe.org/ticket/7455 // $parentField->setShowSearch(true); $parentModeField->addExtraClass('parent-mode'); // CMSMain->currentPageID() automatically sets the homepage, // which we need to counteract in the default selection (which should default to root, ID=0) if ($parentID = $this->getRequest()->getVar('ParentID')) { $parentModeField->setValue('child'); $parentField->setValue((int) $parentID); } else { $parentModeField->setValue('top'); } $actions = new FieldList(FormAction::create("doAdd", _t('CMSMain.Create', "Create"))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true), FormAction::create("doCancel", _t('CMSMain.Cancel', "Cancel"))->addExtraClass('ss-ui-action-destructive ss-ui-action-cancel')->setUseButtonTag(true)); $this->extend('updatePageOptions', $fields); $form = CMSForm::create($this, "AddForm", $fields, $actions)->setHTMLID('Form_AddForm'); $form->setAttribute('data-hints', $this->SiteTreeHints()); $form->setAttribute('data-childfilter', $this->Link('childfilter')); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-add-form stacked cms-content center cms-edit-form ' . $this->BaseCSSClasses()); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); return $form; }
public function getEditForm($id = null, $fields = null) { // get the cmsfields from ModuleManager DataObject $moduleManager = ModuleManager::current_module_manager(); $fields = $moduleManager->getCMSFields(); // what pages is this module active on $modulesGridField = GridField::create("Modules_Gridfield", "Modules", Module::get(), $modulesGridFieldConfig = GridFieldConfig_RecordEditor::create()); // add multiclass dropdown for modules $modulesGridFieldConfig->removeComponentsByType('GridFieldAddNewButton'); $modulesGridFieldConfig->addComponent(new GridFieldAddNewMultiClass()); // add the fields $fields->addFieldToTab('Root.Modules', $modulesGridField); // module positions tab $positionsHtml = '<h2>Module positions</h2>'; $positionsHtml .= '<p class="message info">To change these you need to edit the positions specified in the <code>_config.php</code> file. These are your currently configured positions available:</p>'; foreach (ModuleManager::config()->positions as $position) { $positionsHtml .= '<p>• <strong>' . $position . '</strong><br /> Use in your template with <code>$ModulePosition("' . $position . '");</code></p>'; } $positionsHtml .= '</ul>'; $fields->addFieldToTab('Root.Positions', LiteralField::create('html', $positionsHtml)); // actions $actions = $moduleManager->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($moduleManager); $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); } } 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 * @todo what template is used here? AssetAdmin_UploadContent.ss doesn't seem to be used anymore */ public function getEditForm($id = null, $fields = null) { Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js'); Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css'); $uploadField = CloudinaryUploadField::create('AssetUploadField', ''); $uploadField->setConfig('previewMaxWidth', 40); $uploadField->setConfig('previewMaxHeight', 30); $uploadField->setConfig('changeDetection', false); $uploadField->addExtraClass('ss-assetuploadfield'); $uploadField->removeExtraClass('ss-uploadfield'); $uploadField->setTemplate('AssetUploadField'); $exts = $uploadField->getValidator()->getAllowedExtensions(); asort($exts); $uploadField->Extensions = implode(', ', $exts); $form = CMSForm::create($this, 'EditForm', new FieldList($uploadField), new FieldList())->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses()); // Don't use AssetAdmin_EditForm, as it assumes a different panel structure $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->Fields()->push(new LiteralField('BackLink', sprintf('<a href="%s" class="backlink ss-ui-button cms-panel-link" data-icon="back">%s</a>', singleton('CloudinaryAdmin')->Link('show'), 'Back to files'))); $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; }
public function getEditForm($id = null, $fields = null) { // get the cmsfields from ModuleManager DataObject $moduleManager = ModuleManager::CurrentModuleManager(); $fields = $moduleManager->getCMSFields(); // what pages is this module active on $modulesGridField = GridField::create("Modules_Gridfield", "Modules", Module::get(), $modulesGridFieldConfig = GridFieldConfig_RecordEditor::create()); $modulePositionsGridField = GridField::create("ModulePositions_Gridfield", "Module Positions", ModulePosition::get(), GridFieldConfig_RecordEditor::create()); // add multiclass dropdown for modules $modulesGridFieldConfig->removeComponentsByType('GridFieldAddNewButton'); $modulesGridFieldConfig->addComponent(new GridFieldAddNewMultiClass()); // add the fields $fields->addFieldToTab('Root.Modules', $modulesGridField); $fields->addFieldToTab('Root.ModulePositions', $modulePositionsGridField); $fields->addFieldToTab('Root.ModulePositions', LiteralField::create('html', '<em>To load a position into your template, simply write <code>$ModulePosition(Alias)</code> where <code>Alias</code> is your position alias</em>')); // actions $actions = $moduleManager->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($moduleManager); $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); } } return $form; }
public function AddForm() { $folder = singleton('Folder'); $form = CMSForm::create($this, 'AddForm', new FieldList(new TextField("Name", _t('File.Name')), new HiddenField('ParentID', false, $this->getRequest()->getVar('ParentID'))), new FieldList(FormAction::create('doAdd', _t('AssetAdmin_left_ss.GO', 'Go'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setTitle(_t('AssetAdmin.ActionAdd', 'Add folder'))))->setHTMLID('Form_AddForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('add-form cms-add-form cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses()); return $form; }
public function getEditForm($id = null, $fields = null) { // TODO Duplicate record fetching (see parent implementation) 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); } $memberList = GridField::create('Members', false, Member::get(), $memberListConfig = GridFieldConfig_RecordEditor::create()->addComponent(new GridFieldButtonRow('after'))->addComponent(new GridFieldExportButton('buttons-after-left')))->addExtraClass("members_grid"); if ($record && method_exists($record, 'getValidator')) { $validator = $record->getValidator(); } else { $validator = Injector::inst()->get('Member')->getValidator(); } $memberListConfig->getComponentByType('GridFieldDetailForm')->setValidator($validator); $groupList = GridField::create('Groups', false, Group::get(), GridFieldConfig_RecordEditor::create()); $columns = $groupList->getConfig()->getComponentByType('GridFieldDataColumns'); $columns->setDisplayFields(array('Breadcrumbs' => singleton('Group')->fieldLabel('Title'))); $columns->setFieldFormatting(array('Breadcrumbs' => function ($val, $item) { return Convert::raw2xml($item->getBreadcrumbs(' > ')); })); $fields = new FieldList($root = new TabSet('Root', $usersTab = new Tab('Users', _t('SecurityAdmin.Users', 'Users'), $memberList, new LiteralField('MembersCautionText', sprintf('<p class="caution-remove"><strong>%s</strong></p>', _t('SecurityAdmin.MemberListCaution', 'Caution: Removing members from this list will remove them from all groups and the' . ' database')))), $groupsTab = new Tab('Groups', singleton('Group')->i18n_plural_name(), $groupList)), new HiddenField('ID', false, 0)); // Add import capabilities. Limit to admin since the import logic can affect assigned permissions if (Permission::check('ADMIN')) { $fields->addFieldsToTab('Root.Users', array(new HeaderField(_t('SecurityAdmin.IMPORTUSERS', 'Import users'), 3), new LiteralField('MemberImportFormIframe', sprintf('<iframe src="%s" id="MemberImportFormIframe" width="100%%" height="250px" frameBorder="0">' . '</iframe>', $this->Link('memberimport'))))); $fields->addFieldsToTab('Root.Groups', array(new HeaderField(_t('SecurityAdmin.IMPORTGROUPS', 'Import groups'), 3), new LiteralField('GroupImportFormIframe', sprintf('<iframe src="%s" id="GroupImportFormIframe" width="100%%" height="250px" frameBorder="0">' . '</iframe>', $this->Link('groupimport'))))); } // Tab nav in CMS is rendered through separate template $root->setTemplate('CMSTabSet'); // Add roles editing interface if (Permission::check('APPLY_ROLES')) { $rolesField = GridField::create('Roles', false, PermissionRole::get(), GridFieldConfig_RecordEditor::create()); $rolesTab = $fields->findOrMakeTab('Root.Roles', _t('SecurityAdmin.TABROLES', 'Roles')); $rolesTab->push($rolesField); } $actionParam = $this->getRequest()->param('Action'); if ($actionParam == 'groups') { $groupsTab->addExtraClass('ui-state-active'); } elseif ($actionParam == 'users') { $usersTab->addExtraClass('ui-state-active'); } elseif ($actionParam == 'roles') { $rolesTab->addExtraClass('ui-state-active'); } $actions = new FieldList(); $form = CMSForm::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // Tab nav in CMS is rendered through separate template if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); } $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $this->extend('updateEditForm', $form); return $form; }
public function getEditForm($id = null, $fields = null) { /** * Collecting all definitions above, create our form. */ $form = CMSForm::create($name = $this, $title = 'getEditForm', $fields = self::construct_cms_fields(), $actions = self::construct_cms_actions())->setHTMLID('Form_EditForm')->setResponseNegotiator($this->getResponseNegotiator())->addExtraClass('cms-edit-form center ss-tabset cms-tabset ' . $this->BaseCSSClasses())->setTemplate($this->getTemplatesWithSuffix('_EditForm')); //If a Root Tabset exists in our fields render them with the defined template. $form->Fields()->hasTabset() ? $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet') : null; //Permit the modification of this forms fields through a DataExtension. $this->extend('updateStoreCMSFields', $fields); return $form; }
/** * Returns a placeholder form, used by {@link getEditForm()} if no record is selected. * Our javascript logic always requires a form to be present in the CMS interface. * * @return Form */ public function EmptyForm() { $form = CMSForm::create($this, "EditForm", new FieldList(), new FieldList())->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->unsetValidator(); $form->addExtraClass('cms-edit-form'); $form->addExtraClass('root-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); return $form; }
/** * Returns a GridField of messages * @return CMSForm */ public function getEditForm($id = null, $fields = null) { if (!$id) { $id = $this->currentPageID(); } $form = parent::getEditForm($id); $record = $this->getRecord($id); if ($record && !$record->canView()) { return Security::permissionFailure($this); } // Build gridfield $messageListConfig = GridFieldConfig::create()->addComponents(new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldFooter()); $messages = $this->Messages(); if (is_string($messages)) { // The api returned an error $messagesList = new LiteralField("MessageAlert", '<div class="message bad">' . $messages . '</div>'); } else { $messagesList = GridField::create('Messages', false, $messages, $messageListConfig)->addExtraClass("messages_grid"); $columns = $messageListConfig->getComponentByType('GridFieldDataColumns'); $columns->setDisplayFields(['transmission_id' => _t('SparkPostAdmin.EventTransmissionId', 'Id'), 'timestamp' => _t('SparkPostAdmin.EventDate', 'Date'), 'type' => _t('SparkPostAdmin.EventType', 'Type'), 'rcpt_to' => _t('SparkPostAdmin.EventRecipient', 'Recipient'), 'subject' => _t('SparkPostAdmin.EventSubject', 'Subject'), 'friendly_from' => _t('SparkPostAdmin.EventSender', 'Sender')]); $columns->setFieldFormatting(['timestamp' => function ($value, &$item) { return date('Y-m-d H:i:s', strtotime($value)); }]); // Validator setup $validator = null; if ($record && method_exists($record, 'getValidator')) { $validator = $record->getValidator(); } if ($validator) { $messageListConfig->getComponentByType('GridFieldDetailForm')->setValidator($validator); } } // Create tabs $messagesTab = new Tab('Messages', _t('SparkPostAdmin.Messages', 'Messages'), $messagesList, new HiddenField('ID', false, 0)); $fields = new FieldList($root = new TabSet('Root', $messagesTab)); if ($this->CanConfigureApi()) { $settingsTab = new Tab('Settings', _t('SparkPostAdmin.Settings', 'Settings')); $webhookTabData = $this->WebhookTab(); $settingsTab->push($webhookTabData); $domainTabData = $this->DomainTab(); $settingsTab->push($domainTabData); $fields->addFieldToTab('Root', $settingsTab); } // Tab nav in CMS is rendered through separate template $root->setTemplate('CMSTabSet'); // Manage tabs state $actionParam = $this->getRequest()->param('Action'); if ($actionParam == 'setting') { $settingsTab->addExtraClass('ui-state-active'); } elseif ($actionParam == 'messages') { $messagesTab->addExtraClass('ui-state-active'); } $actions = new FieldList(); // Create cms form $form = CMSForm::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // Tab nav in CMS is rendered through separate template if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); } $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $this->extend('updateEditForm', $form); return $form; }
/** * Gets the form used for viewing snippets * @param {int} $id ID of the record to fetch * @param {FieldList} $fields Fields to use * @return {Form} Form to be used */ public function getEditForm($id = null, $fields = null) { if (!$id) { $id = $this->currentPageID(); } $record = $this->getRecord($id); if ($record && !$record->canView()) { return Security::permissionFailure($this); } if ($record) { $fields = $record->getCMSFields(); $actions = new FieldList(FormAction::create('doSave', _t('CodeBank.SAVE', '_Save'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'), FormAction::create('doCancel', _t('CodeBank.CANCEL', '_Cancel'))); if ($record->canDelete()) { $actions->push(FormAction::create('doDelete', _t('CodeBank.DELETE', '_Delete'))->addExtraClass('ss-ui-action-destructive')); } // Use <button> to allow full jQuery UI styling $actionsFlattened = $actions->dataFields(); if ($actionsFlattened) { foreach ($actionsFlattened as $action) { if ($action instanceof FormAction) { $action->setUseButtonTag(true); } } } if ($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); } else { $validator = new RequiredFields(); } $fields->push(new HiddenField('ID', 'ID')); $form = CMSForm::create($this, 'EditForm', $fields, $actions, $validator)->setHTMLID('Form_EditForm'); $form->loadDataFrom($record); $form->disableDefaultAction(); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->addExtraClass('center ' . $this->BaseCSSClasses()); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $this->extend('updateEditForm', $form); //Display message telling user to run dev/build because the version numbers are out of sync if (CB_VERSION != '@@VERSION@@' && CodeBankConfig::CurrentConfig()->Version != CB_VERSION . ' ' . CB_BUILD_DATE) { $form->insertBefore(new LiteralField('<p class="message error">' . _t('CodeBank.UPDATE_NEEDED', '_A database upgrade is required please run {startlink}dev/build{endlink}.', array('startlink' => '<a href="dev/build?flush=all">', 'endlink' => '</a>')) . '</p>'), 'LanguageID'); } else { if ($this->hasOldTables()) { $form->insertBefore(new LiteralField('<p class="message warning">' . _t('CodeBank.MIGRATION_AVAILABLE', '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.', array('startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">', 'endlink' => '</a>')) . '</p>'), 'LanguageID'); } } $form->Actions()->push(new LiteralField('CodeBankVersion', '<p class="codeBankVersion">Code Bank: ' . $this->getVersion() . '</p>')); Requirements::javascript(CB_DIR . '/javascript/CodeBank.EditForm.js'); return $form; } $form = $this->EmptyForm(); if (Session::get('CodeBank.deletedSnippetID')) { $form->Fields()->push(new HiddenField('ID', 'ID', Session::get('CodeBank.deletedSnippetID'))); } //Display message telling user to run dev/build because the version numbers are out of sync if (CB_VERSION != '@@VERSION@@' && CodeBankConfig::CurrentConfig()->Version != CB_VERSION . ' ' . CB_BUILD_DATE) { $form->push(new LiteralField('<p class="message error">' . _t('CodeBank.UPDATE_NEEDED', '_A database upgrade is required please run {startlink}dev/build{endlink}.', array('startlink' => '<a href="dev/build?flush=all">', 'endlink' => '</a>')) . '</p>')); } else { if ($this->hasOldTables()) { $form->push(new LiteralField('<p class="message warning">' . _t('CodeBank.MIGRATION_AVAILABLE', '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.', array('startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">', 'endlink' => '</a>')) . '</p>')); } } $this->redirect('admin/codeBank/'); return $form; }
/** * Version select form. Main interface between selecting versions to view * and comparing multiple versions. * * Because we can reload the page directly to a compare view (history/compare/1/2/3) * this form has to adapt to those parameters as well. * * @return Form */ public function VersionsForm() { $id = $this->currentPageID(); $page = $this->getRecord($id); $versionsHtml = ''; $action = $this->getRequest()->param('Action'); $versionID = $this->getRequest()->param('VersionID'); $otherVersionID = $this->getRequest()->param('OtherVersionID'); $showUnpublishedChecked = 0; $compareModeChecked = $action == "compare"; if ($page) { $versions = $page->allVersions(); $versionID = !$versionID ? $page->Version : $versionID; if ($versions) { foreach ($versions as $k => $version) { $active = false; if ($version->Version == $versionID || $version->Version == $otherVersionID) { $active = true; if (!$version->WasPublished) { $showUnpublishedChecked = 1; } } $version->Active = $active; } } $vd = new ViewableData(); $versionsHtml = $vd->customise(array('Versions' => $versions))->renderWith('CMSPageHistoryController_versions'); } $fields = new FieldList(new CheckboxField('ShowUnpublished', _t('CMSPageHistoryController.SHOWUNPUBLISHED', 'Show unpublished versions'), $showUnpublishedChecked), new CheckboxField('CompareMode', _t('CMSPageHistoryController.COMPAREMODE', 'Compare mode (select two)'), $compareModeChecked), new LiteralField('VersionsHtml', $versionsHtml), $hiddenID = new HiddenField('ID', false, "")); $actions = new FieldList(new FormAction('doCompare', _t('CMSPageHistoryController.COMPAREVERSIONS', 'Compare Versions')), new FormAction('doShowVersion', _t('CMSPageHistoryController.SHOWVERSION', 'Show Version'))); // Use <button> to allow full jQuery UI styling foreach ($actions->dataFields() as $action) { $action->setUseButtonTag(true); } $form = CMSForm::create($this, 'VersionsForm', $fields, $actions)->setHTMLID('Form_VersionsForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->loadDataFrom($this->getRequest()->requestVars()); $hiddenID->setValue($id); $form->unsetValidator(); $form->addExtraClass('cms-versions-form')->setAttribute('data-link-tmpl-compare', Controller::join_links($this->Link('compare'), '%s', '%s', '%s'))->setAttribute('data-link-tmpl-show', Controller::join_links($this->Link('show'), '%s', '%s')); return $form; }
public function ListViewForm() { $params = $this->request->requestVar('q'); $list = $this->getList($params, $parentID = $this->request->requestVar('ParentID')); $gridFieldConfig = GridFieldConfig::create()->addComponents(new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator(self::config()->page_length)); if ($parentID) { $gridFieldConfig->addComponent(GridFieldLevelup::create($parentID)->setLinkSpec('?ParentID=%d&view=list')->setAttributes(array('data-pjax' => 'ListViewForm,Breadcrumbs'))); } $gridField = new GridField('Page', 'Pages', $list, $gridFieldConfig); $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); // Don't allow navigating into children nodes on filtered lists $fields = array('getTreeTitle' => _t('SiteTree.PAGETITLE', 'Page Title'), 'singular_name' => _t('SiteTree.PAGETYPE'), 'LastEdited' => _t('SiteTree.LASTUPDATED', 'Last Updated')); $gridField->getConfig()->getComponentByType('GridFieldSortableHeader')->setFieldSorting(array('getTreeTitle' => 'Title')); $gridField->getState()->ParentID = $parentID; if (!$params) { $fields = array_merge(array('listChildrenLink' => ''), $fields); } $columns->setDisplayFields($fields); $columns->setFieldCasting(array('Created' => 'Datetime->Ago', 'LastEdited' => 'Datetime->FormatFromSettings', 'getTreeTitle' => 'HTMLText')); $controller = $this; $columns->setFieldFormatting(array('listChildrenLink' => function ($value, &$item) use($controller) { $num = $item ? $item->numChildren() : null; if ($num) { return sprintf('<a class="cms-panel-link list-children-link" data-pjax-target="ListViewForm,Breadcrumbs" href="%s">%s</a>', Controller::join_links($controller->Link(), sprintf("?ParentID=%d&view=list", (int) $item->ID)), $num); } }, 'getTreeTitle' => function ($value, &$item) use($controller) { return sprintf('<a class="action-detail" href="%s">%s</a>', Controller::join_links(singleton('CMSPageEditController')->Link('show'), (int) $item->ID), $item->TreeTitle); })); $listview = CMSForm::create($this, 'ListViewForm', new FieldList($gridField), new FieldList())->setHTMLID('Form_ListViewForm'); $listview->setAttribute('data-pjax-fragment', 'ListViewForm'); $listview->setResponseNegotiator($this->getResponseNegotiator()); $this->extend('updateListView', $listview); $listview->disableSecurityToken(); return $listview; }
/** * Gets the form used for viewing snippets * @param {int} $id ID of the record to fetch * @param {FieldList} $fields Fields to use * @return {Form} Form to be used */ public function getEditForm($id = null, $fields = null) { if (!$id) { $id = $this->currentPageID(); } $form = parent::getEditForm($id); $record = $this->getRecord($id); if ($record && !$record->canView()) { return Security::permissionFailure($this); } if (!$fields) { $fields = $form->Fields(); } $actions = $form->Actions(); if ($record) { $fields->push($idField = new HiddenField("ID", false, $id)); $versions = $record->Versions()->filter('ID:not', $record->CurrentVersionID)->Map('ID', 'Created'); $actions = new FieldList(new FormAction('doCopy', _t('CodeBank.COPY', '_Copy')), new FormAction('doEditRedirect', _t('CodeBank.EDIT', '_Edit')), new FormAction('doExport', _t('CodeBank.EXPORT', '_Export')), new FormAction('doPrint', _t('CodeBank.PRINT', '_Print')), new LabelField('Revision', _t('CodeBank.REVISION', '_Revision') . ': '), DropdownField::create('RevisionID', '', $versions, $this->urlParams['OtherID'])->setEmptyString('{' . _t('CodeBank.CURRENT_REVISION', '_Current Revision') . '}')->setDisabled($record->Versions()->Count() <= 1)->addExtraClass('no-change-track'), FormAction::create('compareRevision', _t('CodeBank.COMPARE_WITH_CURRENT', '_Compare with Current'))->setDisabled($record->Versions()->Count() <= 1 || empty($this->urlParams['OtherID']) || !is_numeric($this->urlParams['OtherID']))); // Use <button> to allow full jQuery UI styling $actionsFlattened = $actions->dataFields(); if ($actionsFlattened) { foreach ($actionsFlattened as $action) { if ($action instanceof FormAction) { $action->setUseButtonTag(true); } } } if ($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); } else { $validator = new RequiredFields(); } if ($record->Package() && $record->Package() !== false && $record->Package()->ID != 0) { $package = new ArrayList(array($record->Package())); } else { $package = null; } $fields->insertBefore($fields->dataFieldByName('Title'), 'LanguageID'); $fields->replaceField('PackageID', new PackageViewField('PackageID', _t('Snippet.PACKAGE', '_Package'), $package, $record->ID)); $fields->replaceField('Text', HighlightedContentField::create('SnippetText', _t('Snippet.CODE', '_Code'), $record->Language()->HighlightCode)->setForm($form)); $fields->replaceField('Tags', new TagsViewField('Tags', _t('Snippet.TAGS_COLUMN', '_Tags'))); $fields->addFieldToTab('Root.Main', $creator = ReadonlyField::create('CreatorName', _t('CodeBank.CREATOR', '_Creator'), $record->Creator() && $record->Creator()->ID > 0 ? '<a href="' . $this->Link() . '?creator=' . $record->CreatorID . '">' . $record->Creator()->Name . '</a>' : _t('CodeBank.UNKNOWN_USER', '_Unknown User'))->setForm($form)); $creator->dontEscape = true; $fields->addFieldToTab('Root.Main', ReadonlyField::create('LanguageName', _t('CodeBank.LANGUAGE', '_Language'), $record->Language()->Name)->setForm($form)); $fields->addFieldToTab('Root.Main', DatetimeField_Readonly::create('LastModified', _t('CodeBank.LAST_MODIFIED', '_Last Modified'), $record->CurrentVersion->LastEdited)->setForm($form)); $fields->addFieldToTab('Root.Main', ReadonlyField::create('LastEditorName', _t('CodeBank.LAST_EDITED_BY', '_Last Edited By'), $record->LastEditor() && $record->LastEditor()->ID > 0 ? $record->LastEditor()->Name : _t('CodeBank.UNKNOWN_USER', '_Unknown User'))->setForm($form)); $fields->addFieldToTab('Root.Main', ReadonlyField::create('SnippetID', _t('CodeBank.ID', '_ID'), $record->ID)); $fields->addFieldToTab('Root.Main', ReadonlyField::create('CurrentVersionID', _t('CodeBank.VERSION', '_Version'))); $fields->push(new HiddenField('ID', 'ID')); $form = new Form($this, 'EditForm', $fields, $actions, $validator); $form->loadDataFrom($record); $form->disableDefaultAction(); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->addExtraClass('center ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); //Swap content for version text if (!empty($this->urlParams['OtherID']) && is_numeric($this->urlParams['OtherID'])) { $version = $record->Version(intval($this->urlParams['OtherID'])); if (!empty($version) && $version !== false && $version->ID != 0) { $fields->dataFieldByName('SnippetText')->setValue($version->Text); $fields->dataFieldByName('LastModified')->setValue($version->LastEdited); $fields->dataFieldByName('CurrentVersionID')->setValue($version->ID); } $form->Fields()->insertBefore(new LiteralField('NotCurrentVersion', '<p class="message warning">' . _t('CodeBank.NOT_CURRENT_VERSION', '_You are viewing a past version of this snippet\'s content, {linkopen}click here{linkclose} to view the current version', array('linkopen' => '<a href="admin/codeBank/show/' . $record->ID . '">', 'linkclose' => '</a>')) . '</p>'), 'Title'); } $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); $this->extend('updateEditForm', $form); $form->Actions()->push(new LiteralField('CodeBankVersion', '<p class="codeBankVersion">Code Bank: ' . $this->getVersion() . '</p>')); Requirements::add_i18n_javascript(CB_DIR . '/javascript/lang'); Requirements::add_i18n_javascript('mysite/javascript/lang'); Requirements::javascript(CB_DIR . '/javascript/external/jquery-zclip/jquery.zclip.min.js'); Requirements::javascript(CB_DIR . '/javascript/CodeBank.ViewForm.js'); //Display message telling user to run dev/build because the version numbers are out of sync if (CB_VERSION != '@@VERSION@@' && CodeBankConfig::CurrentConfig()->Version != CB_VERSION . ' ' . CB_BUILD_DATE) { $form->Fields()->insertBefore(new LiteralField('DBUpgrade', '<p class="message error">' . _t('CodeBank.UPDATE_NEEDED', '_A database upgrade is required please run {startlink}dev/build{endlink}.', array('startlink' => '<a href="dev/build?flush=all">', 'endlink' => '</a>')) . '</p>'), 'Title'); } else { if ($this->hasOldTables()) { $form->Fields()->insertBefore(new LiteralField('DBUpgrade', '<p class="message warning">' . _t('CodeBank.MIGRATION_AVAILABLE', '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.', array('startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">', 'endlink' => '</a>')) . '</p>'), 'Title'); } } return $form; } else { if ($id) { $form = CMSForm::create($this, 'EditForm', new FieldList(new TabSet('Root', new Tab('Main', ' ', new LabelField('DoesntExistLabel', _t('CodeBank.SNIPPIT_NOT_EXIST', '_Snippit does not exist'))))), new FieldList())->setHTMLID('Form_EditForm'); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->addExtraClass('center ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); //Display message telling user to run dev/build because the version numbers are out of sync if (CB_VERSION != '@@VERSION@@' && CodeBankConfig::CurrentConfig()->Version != CB_VERSION . ' ' . CB_BUILD_DATE) { $form->Fields()->insertBefore(new LiteralField('DBUpgrade', '<p class="message error">' . _t('CodeBank.UPDATE_NEEDED', '_A database upgrade is required please run {startlink}dev/build{endlink}.', array('startlink' => '<a href="dev/build?flush=all">', 'endlink' => '</a>')) . '</p>'), 'DoesntExist'); } else { if ($this->hasOldTables()) { $form->Fields()->insertBefore(new LiteralField('DBUpgrade', '<p class="message warning">' . _t('CodeBank.MIGRATION_AVAILABLE', '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.', array('startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">', 'endlink' => '</a>')) . '</p>'), 'DoesntExistLabel'); } } } else { $form = $this->EmptyForm(); if (Session::get('CodeBank.deletedSnippetID')) { $form->Fields()->push(new HiddenField('ID', 'ID', Session::get('CodeBank.deletedSnippetID'))); } //Display message telling user to run dev/build because the version numbers are out of sync if (CB_VERSION != '@@VERSION@@' && CodeBankConfig::CurrentConfig()->Version != CB_VERSION . ' ' . CB_BUILD_DATE) { $form->Fields()->push(new LiteralField('DBUpgrade', '<p class="message error">' . _t('CodeBank.UPDATE_NEEDED', '_A database upgrade is required please run {startlink}dev/build{endlink}.', array('startlink' => '<a href="dev/build?flush=all">', 'endlink' => '</a>')) . '</p>')); } else { if ($this->hasOldTables()) { $form->Fields()->push(new LiteralField('DBUpgrade', '<p class="message warning">' . _t('CodeBank.MIGRATION_AVAILABLE', '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.', array('startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">', 'endlink' => '</a>')) . '</p>')); } } } } $form->disableDefaultAction(); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->addExtraClass('center ' . $this->BaseCSSClasses()); $form->Actions()->push(new LiteralField('CodeBankVersion', '<p class="codeBankVersion">Code Bank: ' . $this->getVersion() . '</p>')); return $form; }
/** * Returns a GridField of messages * @return CMSForm */ public function ListForm() { $fields = new FieldList(); $gridFieldConfig = GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldFooter()); $gridField = new GridField('SearchResults', _t('MandrillAdmin.SearchResults', 'Search Results'), $this->Messages(), $gridFieldConfig); $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); $columns->setDisplayFields(array('date' => _t('MandrillAdmin.MessageDate', 'Date'), 'state' => _t('MandrillAdmin.MessageStatus', 'Status'), 'sender' => _t('MandrillAdmin.MessageSender', 'Sender'), 'email' => _t('MandrillAdmin.MessageEmail', 'Email'), 'subject' => _t('MandrillAdmin.MessageSubject', 'Subject'), 'opens' => _t('MandrillAdmin.MessageOpens', 'Opens'), 'clicks' => _t('MandrillAdmin.MessageClicks', 'Clicks'))); $columns->setFieldFormatting(array('subject' => function ($value, &$item) { return sprintf('<a href="%s" class="cms-panel-link" data-pjax-target="Content">%s</a>', Convert::raw2xml($item->Link), $value); }, 'state' => function ($value, &$item) { $color = MandrillMessage::getColorForState($value); return sprintf('<span style="color:%s">%s</span>', $color, $value); })); $gridField->addExtraClass('all-messages-gridfield'); $fields->push($gridField); $actions = new FieldList(); $form = CMSForm::create($this, "ListForm", $fields, $actions)->setHTMLID('Form_ListForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); return $form; }
/** * Returns a Form for adding a new field for use in templates. * Can be modified from a decorator by a 'updateAddNewForm' method * * @return CMSForm */ public function AddForm() { // List of creatable form fields $typeDropdown = new DropdownField('Type', _t('EditableFieldAdmin.SELECTAFIELD', 'Select a Field'), $this->getCreatableFields()); $typeDropdown->setEmptyString(' '); // Form fields $fields = new FieldList($typeDropdown); // Form add button $actions = new FieldList(FormAction::create('doAddField', _t('EditableField.ADD', 'Add'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'add')->setUseButtonTag(true)); // Form validators $validator = new RequiredFields(); // Create the form $form = CMSForm::create($this, 'AddNewForm', $fields, $actions, $validator)->addExtraClass('cms-search-form')->setFormMethod('POST')->setFormAction($this->Link('doAdd')); // Allow decorators to modify the form $this->extend('updateAddNewForm', $form); return $form; }
public function getEditForm($id = null, $fields = null) { $report = $this->reportObject; if ($report) { $fields = $report->getCMSFields(); } else { // List all reports $fields = new FieldList(); $gridFieldConfig = GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldFooter()); $gridField = new GridField('Reports', false, $this->Reports(), $gridFieldConfig); $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); $columns->setDisplayFields(array('title' => _t('ReportAdmin.ReportTitle', 'Title'))); $columns->setFieldFormatting(array('title' => function ($value, &$item) { return sprintf('<a href="%s" class="cms-panel-link">%s</a>', Convert::raw2xml($item->Link), Convert::raw2xml($value)); })); $gridField->addExtraClass('all-reports-gridfield'); $fields->push($gridField); } $actions = new FieldList(); $form = CMSForm::create($this, "EditForm", $fields, $actions)->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses()); $form->loadDataFrom($this->request->getVars()); $this->extend('updateEditForm', $form); return $form; }