/** * @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; }
/** * @return Form */ function AddForm() { $record = $this->currentPage(); $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')] = $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($hintsField = new LiteralField('Hints', sprintf('<span class="hints" data-hints="%s"></span>', $this->SiteTreeHints())), new LiteralField('PageModeHeader', sprintf($numericLabelTmpl, 1, _t('CMSMain.ChoosePageParentMode', 'Choose where to create this page'))), $parentModeField = new SelectionGroup("ParentModeField", array("top//{$topTitle}" => null, "child//{$childTitle}" => $parentField = new TreeDropdownField("ParentID", "", 'SiteTree', 'ID', 'TreeTitle'))), $typeField = new OptionsetField("PageType", sprintf($numericLabelTmpl, 2, _t('CMSMain.ChoosePageType', 'Choose page type')), $pageTypes, 'Page')); // TODO Re-enable search once it allows for HTML title display, // see http://open.silverstripe.org/ticket/7455 // $parentField->setShowSearch(true); $parentModeField->setValue($this->request->getVar('ParentID') ? 'child' : 'top'); $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) $homepageSegment = RootURLController::get_homepage_link(); if ($record && $record->URLSegment != $homepageSegment) { $parentField->setValue($record->ID); } $actions = new FieldList(FormAction::create("doAdd", _t('CMSMain.Create', "Create"))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true)); $this->extend('updatePageOptions', $fields); $form = new Form($this, "AddForm", $fields, $actions); $form->addExtraClass('cms-add-form stacked cms-content center cms-edit-form ' . $this->BaseCSSClasses()); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); if ($parentID = $this->request->getVar('ParentID')) { $form->Fields()->dataFieldByName('ParentID')->setValue((int) $parentID); } return $form; }
/** * @return Form */ function AddForm() { // If request send from rightclick-submenu, directly add Page if(($pageType = $this->request->getVar('Type')) && ($parentID = $this->request->getVar('ParentID'))) { $data = array( "PageType" => (string)$pageType, "ParentID" => $parentID, "ParentModeField" => "child" ); $this->doAdd($data, null); return; } $record = $this->currentPage(); $pageTypes = array(); foreach($this->PageTypes() as $type) { $html = sprintf('<span class="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>'; $topTitle = _t('CMSPageAddController.ParentMode_top', 'Top level'); $childTitle = _t('CMSPageAddController.ParentMode_child', 'Under another page'); $fields = new FieldList( // new HiddenField("ParentID", false, ($this->parentRecord) ? $this->parentRecord->ID : null), // TODO Should be part of the form attribute, but not possible in current form API $hintsField = new LiteralField('Hints', sprintf('<span class="hints" data-hints="%s"></span>', $this->SiteTreeHints())), new LiteralField('PageModeHeader', sprintf($numericLabelTmpl, 1, _t('CMSMain.ChoosePageParentMode', 'Choose where to create this page'))), $parentModeField = new SelectionGroup( "ParentModeField", array( "top//$topTitle" => null, //new LiteralField("Dummy", ''), "child//$childTitle" => $parentField = new TreeDropdownField( "ParentID", "", 'SiteTree' ) ) ), $typeField = new OptionsetField( "PageType", sprintf($numericLabelTmpl, 2, _t('CMSMain.ChoosePageType', 'Choose page type')), $pageTypes, 'Page' ) ); $parentField->setShowSearch(true); $parentModeField->setValue($this->request->getVar('ParentID') ? 'child' : 'top'); $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) $homepageSegment = RootURLController::get_homepage_link(); if($record && $record->URLSegment != $homepageSegment) { $parentField->setValue($record->ID); } $actions = new FieldList( // $resetAction = new ResetFormAction('doCancel', _t('CMSMain.Cancel', 'Cancel')), FormAction::create("doAdd", _t('CMSMain.Create',"Create")) ->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept') ->setUseButtonTag(true) ); $this->extend('updatePageOptions', $fields); $form = new Form($this, "AddForm", $fields, $actions); $form->addExtraClass('cms-add-form stacked cms-content center cms-edit-form ' . $this->BaseCSSClasses()); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); if($parentID = $this->request->getVar('ParentID')) { $form->Fields()->dataFieldByName('ParentID')->setValue((int)$parentID); } return $form; }