public function getCMSFields() { $path = '/' . dirname($this->getFilename()); $previewLink = Convert::raw2att($this->PreviewLink()); $image = "<img src=\"{$previewLink}\" class=\"editor__thumbnail\" />"; $link = $this->Link(); $statusTitle = $this->getStatusTitle(); $statusFlag = "<span class=\"editor__status-flag\">{$statusTitle}</span>"; $content = Tab::create('Main', HeaderField::create('TitleHeader', $this->Title, 1)->addExtraClass('editor__heading'), LiteralField::create("ImageFull", $image)->addExtraClass('editor__file-preview'), TabSet::create('Editor', Tab::create('Details', TextField::create("Title", $this->fieldLabel('Title')), TextField::create("Name", $this->fieldLabel('Filename')), ReadonlyField::create("Path", _t('AssetTableField.PATH', 'Path'), ($path !== '/.' ? $path : '') . '/'), HTMLReadonlyField::create('ClickableURL', _t('AssetTableField.URL', 'URL'), sprintf('<i class="%s"></i><a href="%s" target="_blank">%s</a>', 'font-icon-link btn--icon-large form-control-static__icon', $link, $link))), Tab::create('Usage', DatetimeField::create("Created", _t('AssetTableField.CREATED', 'First uploaded'))->setReadonly(true), DatetimeField::create("LastEdited", _t('AssetTableField.LASTEDIT', 'Last changed'))->setReadonly(true))), HiddenField::create('ID', $this->ID)); if ($dimensions = $this->getDimensions()) { $content->insertAfter('TitleHeader', LiteralField::create("DisplaySize", sprintf('<div class="editor__specs">%spx, %s %s</div>', $dimensions, $this->getSize(), $statusFlag))); } else { $content->insertAfter('TitleHeader', LiteralField::create('StatusFlag', $statusFlag)); } $fields = FieldList::create(TabSet::create('Root', $content)); $this->extend('updateCMSFields', $fields); return $fields; }
/** * @todo check actual placement of fields */ public function testInsertAfterWithNestedTabsets() { $FieldListA = new FieldList($tabSetA = new TabSet('TabSet_A', $tabA1 = new Tab('Tab_A1', new TextField('A_pre'), new TextField('A'), new TextField('A_post')), $tabB1 = new Tab('Tab_B1', new TextField('B')))); $tabSetA->insertAfter($A_insertafter = new TextField('A_insertafter'), 'A'); $this->assertEquals($FieldListA->dataFieldByName('A_insertafter'), $A_insertafter, 'Field on toplevel tab can be inserted after'); $this->assertEquals(0, $tabA1->fieldPosition('A_pre')); $this->assertEquals(1, $tabA1->fieldPosition('A')); $this->assertEquals(2, $tabA1->fieldPosition('A_insertafter')); $this->assertEquals(3, $tabA1->fieldPosition('A_post')); $FieldListB = new FieldList(new TabSet('TabSet_A', $tabsetB = new TabSet('TabSet_B', $tabB1 = new Tab('Tab_B1', new TextField('C')), $tabB2 = new Tab('Tab_B2', new TextField('B_pre'), new TextField('B'), new TextField('B_post'))))); $FieldListB->insertAfter($B_insertafter = new TextField('B_insertafter'), 'B'); $this->assertSame($FieldListB->dataFieldByName('B_insertafter'), $B_insertafter, 'Field on nested tab can be inserted after'); $this->assertEquals(0, $tabB2->fieldPosition('B_pre')); $this->assertEquals(1, $tabB2->fieldPosition('B')); $this->assertEquals(2, $tabB2->fieldPosition('B_insertafter')); $this->assertEquals(3, $tabB2->fieldPosition('B_post')); }
protected function getFormFieldHistoryTab($record, $context = []) { return Tab::create('History', HistoryListField::create('HistoryList')->setRecord($record)); }
/** * @inheritdoc */ public function updateCMSFields(FieldList $fields) { $analyticsFields = FieldList::create(TextField::create("GoogleAnalyticsTrackingID", "Google Analytics Tracking ID")->setDescription("e.g. UA-XXXXXX-X"), TextareaField::create("GoogleAnalyticsParameters", "Additional Parameters")->setDescription("<strong>Advanced users only.</strong>\n\t\t\t\t\tIf you do not know what this field does, please leave it blank."), TextareaField::create("GoogleAnalyticsConstructorParameters", "Constructor Parameters")->setDescription("<strong>Advanced users only.</strong>\n\t\t\t\t\tIf you do not know what this field does, please leave it blank. An object to be\n\t\t\t\t\tpassed as an argument to ga.create()")); $fields->addFieldToTab('Root', Tab::create('GoogleAnalytics')->setChildren($analyticsFields)); }
/** * Build "details" formfield tab * * @param File $record * @param array $context * @return Tab */ protected function getFormFieldDetailsTab($record, $context = []) { return Tab::create('Details', TextField::create('Name', File::singleton()->fieldLabel('Filename'))); }
/** * Return the FieldList used to edit this folder in the CMS. * You can modify this FieldList by subclassing folder, or by creating a {@link DataExtension} * and implemeting updateCMSFields(FieldList $fields) on that extension. * * @return FieldList */ public function getCMSFields() { // Don't show readonly path until we can implement parent folder selection, // it's too confusing when readonly (makes sense for files only). $width = (int) Image::config()->get('asset_preview_width'); $previewLink = Convert::raw2att($this->ScaleMaxWidth($width)->getIcon()); $image = "<img src=\"{$previewLink}\" class=\"editor__thumbnail\" />"; $content = Tab::create('Main', HeaderField::create('TitleHeader', $this->Title, 1)->addExtraClass('editor__heading'), LiteralField::create("IconFull", $image)->addExtraClass('editor__file-preview'), TabSet::create('Editor', Tab::create('Details', TextField::create("Name", $this->fieldLabel('Filename')))), HiddenField::create('ID', $this->ID)); $fields = FieldList::create(TabSet::create('Root', $content)); $this->extend('updateCMSFields', $fields); return $fields; }
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 = Member::singleton()->getValidator(); } /** @var GridFieldDetailForm $detailForm */ $detailForm = $memberListConfig->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDetailForm'); $detailForm->setValidator($validator); $groupList = GridField::create('Groups', false, Group::get(), GridFieldConfig_RecordEditor::create()); /** @var GridFieldDataColumns $columns */ $columns = $groupList->getConfig()->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); $columns->setDisplayFields(array('Breadcrumbs' => Group::singleton()->fieldLabel('Title'))); $columns->setFieldFormatting(array('Breadcrumbs' => function ($val, $item) { /** @var Group $item */ return Convert::raw2xml($item->getBreadcrumbs(' > ')); })); $fields = new FieldList($root = new TabSet('Root', $usersTab = new Tab('Users', _t('SecurityAdmin.Users', 'Users'), new LiteralField('MembersCautionText', sprintf('<div class="alert alert-warning" role="alert">%s</div>', _t('SecurityAdmin.MemberListCaution', 'Caution: Removing members from this list will remove them from all groups and the database'))), $memberList), $groupsTab = new Tab('Groups', singleton('SilverStripe\\Security\\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('ImportUsersHeader', _t('SecurityAdmin.IMPORTUSERS', 'Import users'), 3), new LiteralField('MemberImportFormIframe', sprintf('<iframe src="%s" id="MemberImportFormIframe" width="100%%" height="330px" frameBorder="0">' . '</iframe>', $this->Link('memberimport'))))); $fields->addFieldsToTab('Root.Groups', array(new HeaderField('ImportGroupsHeader', _t('SecurityAdmin.IMPORTGROUPS', 'Import groups'), 3), new LiteralField('GroupImportFormIframe', sprintf('<iframe src="%s" id="GroupImportFormIframe" width="100%%" height="330px" frameBorder="0">' . '</iframe>', $this->Link('groupimport'))))); } // Tab nav in CMS is rendered through separate template $root->setTemplate('SilverStripe\\Forms\\CMSTabSet'); // Add roles editing interface $rolesTab = null; 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) { $rolesTab->addExtraClass('ui-state-active'); } $actions = new FieldList(); $form = Form::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm'); $form->addExtraClass('cms-edit-form fill-height'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // Tab nav in CMS is rendered through separate template if ($form->Fields()->hasTabSet()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); } $form->addExtraClass('ss-tabset cms-tabset ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $this->extend('updateEditForm', $form); return $form; }
/** * Gets the form fields as defined through the metadata * on {@link $obj} and the custom parameters passed to FormScaffolder. * Depending on those parameters, the fields can be used in ajax-context, * contain {@link TabSet}s etc. * * @return FieldList */ public function getFieldList() { $fields = new FieldList(); // tabbed or untabbed if ($this->tabbed) { $fields->push(new TabSet("Root", $mainTab = new Tab("Main"))); $mainTab->setTitle(_t('SiteTree.TABMAIN', "Main")); } // Add logical fields directly specified in db config foreach ($this->obj->config()->db as $fieldName => $fieldType) { // Skip restricted fields if ($this->restrictFields && !in_array($fieldName, $this->restrictFields)) { continue; } // @todo Pass localized title if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) { $fieldClass = $this->fieldClasses[$fieldName]; $fieldObject = new $fieldClass($fieldName); } else { $fieldObject = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray()); } // Allow fields to opt-out of scaffolding if (!$fieldObject) { continue; } $fieldObject->setTitle($this->obj->fieldLabel($fieldName)); if ($this->tabbed) { $fields->addFieldToTab("Root.Main", $fieldObject); } else { $fields->push($fieldObject); } } // add has_one relation fields if ($this->obj->hasOne()) { foreach ($this->obj->hasOne() as $relationship => $component) { if ($this->restrictFields && !in_array($relationship, $this->restrictFields)) { continue; } $fieldName = $component === 'SilverStripe\\ORM\\DataObject' ? $relationship : "{$relationship}ID"; if ($this->fieldClasses && isset($this->fieldClasses[$fieldName])) { $fieldClass = $this->fieldClasses[$fieldName]; $hasOneField = new $fieldClass($fieldName); } else { $hasOneField = $this->obj->dbObject($fieldName)->scaffoldFormField(null, $this->getParamsArray()); } if (empty($hasOneField)) { continue; } // Allow fields to opt out of scaffolding $hasOneField->setTitle($this->obj->fieldLabel($relationship)); if ($this->tabbed) { $fields->addFieldToTab("Root.Main", $hasOneField); } else { $fields->push($hasOneField); } } } // only add relational fields if an ID is present if ($this->obj->ID) { // add has_many relation fields if ($this->obj->hasMany() && ($this->includeRelations === true || isset($this->includeRelations['has_many']))) { foreach ($this->obj->hasMany() as $relationship => $component) { if ($this->tabbed) { $fields->findOrMakeTab("Root.{$relationship}", $this->obj->fieldLabel($relationship)); } $fieldClass = isset($this->fieldClasses[$relationship]) ? $this->fieldClasses[$relationship] : 'SilverStripe\\Forms\\GridField\\GridField'; /** @var GridField $grid */ $grid = Object::create($fieldClass, $relationship, $this->obj->fieldLabel($relationship), $this->obj->{$relationship}(), GridFieldConfig_RelationEditor::create()); if ($this->tabbed) { $fields->addFieldToTab("Root.{$relationship}", $grid); } else { $fields->push($grid); } } } if ($this->obj->manyMany() && ($this->includeRelations === true || isset($this->includeRelations['many_many']))) { foreach ($this->obj->manyMany() as $relationship => $component) { if ($this->tabbed) { $fields->findOrMakeTab("Root.{$relationship}", $this->obj->fieldLabel($relationship)); } $fieldClass = isset($this->fieldClasses[$relationship]) ? $this->fieldClasses[$relationship] : 'SilverStripe\\Forms\\GridField\\GridField'; /** @var GridField $grid */ $grid = Object::create($fieldClass, $relationship, $this->obj->fieldLabel($relationship), $this->obj->{$relationship}(), GridFieldConfig_RelationEditor::create()); if ($this->tabbed) { $fields->addFieldToTab("Root.{$relationship}", $grid); } else { $fields->push($grid); } } } } return $fields; }