本文整理汇总了PHP中CMSForm::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CMSForm::create方法的具体用法?PHP CMSForm::create怎么用?PHP CMSForm::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMSForm
的用法示例。
在下文中一共展示了CMSForm::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getEditForm
/**
* @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;
}
示例2: MockChildrenForm
/**
* 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;
}
示例3: getEditForm
/**
* @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;
}
示例4: getEditForm
/**
* @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;
}
示例5: getEditForm
/**
* 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;
}
示例6: getEditForm
/**
* @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;
}
示例7: getEditForm
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;
}
示例8: AddForm
/**
* 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;
}
示例9: getEditForm
/**
*
* @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;
}
示例10: buildForm
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;
}
示例11: getEditForm
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;
}
示例12: getEditForm
/**
* @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;
}
示例13: AddForm
/**
* @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;
}
示例14: getEditForm
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;
}
示例15: getEditForm
/**
* @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;
}