public function setValue($value) { if ($value) { self::set_last_folder($value); } parent::setValue($value); }
public function AddForm() { $form = parent::AddForm(); $fields = $form->Fields(); $fields->push(new HiddenField('Parent', null, true)); // Enforce a parent mode of "child" to correctly read the "allowed children". $fields->dataFieldByName('ParentModeField')->setValue('child'); $fields->insertAfter($parent = new TreeDropdownField('ParentID', '', 'SiteTree', 'ID', 'TreeTitle'), 'ParentModeField'); $parentID = $this->request->getVar('ParentID'); $parentID = $parentID ? $parentID : Multisites::inst()->getCurrentSiteId(); $parent->setForm($form); $parent->setValue((int) $parentID); $form->setValidator(new RequiredFields('ParentID')); 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; }
/** * @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; }
/** * @param $folderID The ID of the folder to display. * @return FormField */ protected function getListField($folderID) { // Generate the folder selection field. $folderField = new TreeDropdownField('ParentID', _t('HtmlEditorField.FOLDER', 'Folder'), 'Folder'); $folderField->setValue($folderID); // Generate the file list field. $config = GridFieldConfig::create(); $config->addComponent(new GridFieldSortableHeader()); $config->addComponent(new GridFieldFilterHeader()); $config->addComponent($columns = new GridFieldDataColumns()); $columns->setDisplayFields(array('StripThumbnail' => '', 'Name' => 'Name', 'Title' => 'Title')); $config->addComponent(new GridFieldPaginator(8)); // If relation is to be autoset, we need to make sure we only list compatible objects. $baseClass = $this->parent->getRelationAutosetClass(); // Create the data source for the list of files within the current directory. $files = DataList::create($baseClass)->filter('ParentID', $folderID); $fileField = new GridField('Files', false, $files, $config); $fileField->setAttribute('data-selectable', true); if ($this->parent->getAllowedMaxFileNumber() !== 1) { $fileField->setAttribute('data-multiselect', true); } $selectComposite = new CompositeField($folderField, $fileField); return $selectComposite; }
/** * @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; }
/** * Returns the form used to create new pages. If the current form is not set * (ie the user is NOT currently editing), then we just return null. * * @return Form */ public function CreatePageForm() { $createOptions = array('child' => 'As a child of the selected page', 'sibling' => 'As a sibling of the selected page'); $pageTree = new TreeDropdownField('CreateContext', _t('WikiPage.CREATE_CONTEXT', 'Select an existing page'), 'WikiPage'); $pageTree->setValue($this->ID); $pageTree->setTreeBaseID($this->data()->getWikiRoot()->ID); $fields = FieldList::create(new TextField('NewPageName', _t('WikiPage.NEW_PAGE_NAME', 'New Page Name')), $pageTree, new OptionsetField('CreateType', _t('WikiPage.CREATE_OPTIONS', 'and create the new page '), $createOptions, 'child')); $actions = FieldList::create(new FormAction('addpage', _t('WikiPage.ADD_PAGE', 'Create'))); return new Form($this, 'CreatePageForm', $fields, $actions); }
/** * @param $folderID The ID of the folder to display. * @return FormField */ protected function getListField($folderID) { // Generate the folder selection field. $folderField = new TreeDropdownField('ParentID', _t('HtmlEditorField.FOLDER', 'Folder'), 'Folder'); $folderField->setValue($folderID); // Generate the file list field. $config = GridFieldConfig::create(); $config->addComponent(new GridFieldSortableHeader()); $config->addComponent(new GridFieldFilterHeader()); $config->addComponent(new GridFieldDataColumns()); $config->addComponent(new GridFieldPaginator(10)); // If relation is to be autoset, we need to make sure we only list compatible objects. $baseClass = null; if ($this->parent->relationAutoSetting) { $baseClass = $this->parent->getRelationAutosetClass(); } // By default we can attach anything that is a file, or derives from file. if (!$baseClass) { $baseClass = 'File'; } // Create the data source for the list of files within the current directory. $files = DataList::create($baseClass)->filter('ParentID', $folderID); $fileField = new GridField('Files', false, $files, $config); $fileField->setAttribute('data-selectable', true); if ($this->parent->getConfig('allowedMaxFileNumber') > 1) { $fileField->setAttribute('data-multiselect', true); } $selectComposite = new CompositeField($folderField, $fileField); return $selectComposite; }
/** * @param $folderID The ID of the folder to display. * @return FormField */ protected function getListField($folderID) { // Generate the folder selection field. $folderField = new TreeDropdownField('ParentID', _t('HtmlEditorField.FOLDER', 'Folder'), 'Folder'); $folderField->setValue($folderID); // Generate the file list field. $config = GridFieldConfig::create(); $config->addComponent(new GridFieldSortableHeader()); $config->addComponent(new GridFieldFilterHeader()); $config->addComponent(new GridFieldDataColumns()); $config->addComponent(new GridFieldPaginator(10)); // Create the data source for the list of files within the current directory. $files = DataList::create('File')->filter('ParentID', $folderID); // If relation is to be autoset, make sure only objects from related class are listed. if ($this->parent->relationAutoSetting) { if ($relationClass = $this->parent->getRelationAutosetClass()) { $files->filter('ClassName', $relationClass); } } $fileField = new GridField('Files', false, $files, $config); $fileField->setAttribute('data-selectable', true); if($this->parent->getConfig('allowedMaxFileNumber') > 1) $fileField->setAttribute('data-multiselect', true); $selectComposite = new CompositeField( $folderField, $fileField ); return $selectComposite; }
/** * @return Form */ function AddForm() { $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; } $fields = new FieldSet($hintsField = new LiteralField('Hints', sprintf('<span class="hints" data-hints="%s"></span>', $this->SiteTreeHints())), $parentField = new TreeDropdownField("ParentID", _t('CMSMain.AddFormParentLabel', 'Parent page'), 'SiteTree'), new OptionsetField("PageType", "", $pageTypes, 'Page')); $parentField->setValue($record ? $record->ID : null); $actions = new FieldSet($createAction = new FormAction("doAdd", _t('CMSMain.Create', "Create"))); // $resetAction->addExtraClass('ss-ui-action-destructive'); $createAction->addExtraClass('ss-ui-action-constructive'); $this->extend('updatePageOptions', $fields); $form = new Form($this, "AddForm", $fields, $actions); $form->addExtraClass('cms-add-form'); return $form; }
/** * @param int $folderID The ID of the folder to display. * @return FormField */ protected function getListField($folderID) { // Generate the folder selection field. $folderField = new TreeDropdownField('ParentID', _t('HTMLEditorField.FOLDER', 'Folder'), 'Folder'); $folderField->setValue($folderID); // Generate the file list field. $config = GridFieldConfig::create(); $config->addComponent(new GridFieldSortableHeader()); $config->addComponent(new GridFieldFilterHeader()); $config->addComponent($colsComponent = new GridFieldDataColumns()); $colsComponent->setDisplayFields(array('StripThumbnail' => '', 'Title' => singleton('File')->fieldLabel('Title'), 'Created' => singleton('File')->fieldLabel('Created'), 'Size' => singleton('File')->fieldLabel('Size'))); $colsComponent->setFieldCasting(array('Created' => 'DBDatetime->Nice')); // Set configurable pagination for file list field $pageSize = Config::inst()->get(get_class($this), 'page_size'); $config->addComponent(new GridFieldPaginator($pageSize)); // If relation is to be autoset, we need to make sure we only list compatible objects. $baseClass = $this->parent->getRelationAutosetClass(); // Create the data source for the list of files within the current directory. $files = DataList::create($baseClass)->exclude('ClassName', 'Folder'); if ($folderID) { $files = $files->filter('ParentID', $folderID); } $fileField = new GridField('Files', false, $files, $config); $fileField->setAttribute('data-selectable', true); if ($this->parent->getAllowedMaxFileNumber() !== 1) { $fileField->setAttribute('data-multiselect', true); } $selectComposite = new CompositeField($folderField, $fileField); return $selectComposite; }