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(); } $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('SilverStripe\\Security\\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'), 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(_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 = Form::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm'); $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; }
function getEditForm($id = null) { $form = parent::getEditForm($id); if (!$id) { $id = $this->currentPageID(); } if ($id && is_numeric($id)) { $fields = $form->Fields(); if ($fields->hasTabSet()) { $fields->findOrMakeTab('Root.Import', _t('Group.IMPORTTABTITLE', 'Import')); $fields->addFieldToTab('Root.Import', new LiteralField('MemberImportFormIframe', sprintf('<iframe src="%s" id="MemberImportFormIframe" width="100%%" height="400px" border="0"></iframe>', $this->Link('memberimport')))); if (Permission::check('APPLY_ROLES')) { $fields->addFieldToTab('Root.Roles', new LiteralField('RolesAddEditLink', sprintf('<p class="add-role"><a href="%s">%s</a></p>', $this->Link('show/root'), _t('Group.RolesAddEditLink', 'Add/edit roles')))); } } $form->Actions()->insertBefore($actionAddMember = new FormAction('addmember', _t('SecurityAdmin.ADDMEMBER', 'Add Member')), 'action_save'); $actionAddMember->setForm($form); // Filter permissions $permissionField = $form->Fields()->dataFieldByName('Permissions'); if ($permissionField) { $permissionField->setHiddenPermissions(self::$hidden_permissions); } } $this->extend('updateEditForm', $form); return $form; }
/** * @return Form */ 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); } $commentsConfig = GridFieldConfig::create()->addComponents(new GridFieldFilterHeader(), new GridFieldDataColumns(), new GridFieldSortableHeader(), new GridFieldPaginator(25), new GridFieldDeleteAction(), new GridFieldDetailForm(), new GridFieldExportButton(), new GridFieldEditButton(), new GridFieldDetailForm()); $needs = new GridField('Comments', _t('CommentsAdmin.NeedsModeration', 'Needs Moderation'), Comment::get()->where('Moderated = 0'), $commentsConfig); $moderated = new GridField('CommentsModerated', _t('CommentsAdmin.CommentsModerated'), Comment::get()->where('Moderated = 1'), $commentsConfig); $fields = new FieldList($root = new TabSet('Root', new Tab('NeedsModeration', _t('CommentAdmin.NeedsModeration', 'Needs Moderation'), $needs), new Tab('Comments', _t('CommentAdmin.Moderated', 'Moderated'), $moderated))); $root->setTemplate('CMSTabSet'); $actions = new FieldList(); $form = new Form($this, 'EditForm', $fields, $actions); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); } $this->extend('updateEditForm', $form); return $form; }
/** * @return Form */ 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); } $newComments = Comment::get()->filter('Moderated', 0); $newGrid = new CommentsGridField('NewComments', _t('CommentsAdmin.NewComments', 'New'), $newComments, CommentsGridFieldConfig::create()); $approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0); $approvedGrid = new CommentsGridField('ApprovedComments', _t('CommentsAdmin.ApprovedComments', 'Approved'), $approvedComments, CommentsGridFieldConfig::create()); $spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1); $spamGrid = new CommentsGridField('SpamComments', _t('CommentsAdmin.SpamComments', 'Spam'), $spamComments, CommentsGridFieldConfig::create()); $newCount = '(' . count($newComments) . ')'; $approvedCount = '(' . count($approvedComments) . ')'; $spamCount = '(' . count($spamComments) . ')'; $fields = new FieldList($root = new TabSet('Root', new Tab('NewComments', _t('CommentAdmin.NewComments', 'New') . ' ' . $newCount, $newGrid), new Tab('ApprovedComments', _t('CommentAdmin.ApprovedComments', 'Approved') . ' ' . $approvedCount, $approvedGrid), new Tab('SpamComments', _t('CommentAdmin.SpamComments', 'Spam') . ' ' . $spamCount, $spamGrid))); $root->setTemplate('CMSTabSet'); $actions = new FieldList(); $form = new Form($this, 'EditForm', $fields, $actions); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); } $this->extend('updateEditForm', $form); return $form; }
public function getEditForm($id = null, $fields = null) { $form = parent::getEditForm($id, $fields); $fields = $form->Fields(); $title = _t('AssetAdmin.FILES', 'Files'); // File listing $gridFieldConfig = GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldSortableHeader(), new GridFieldFilterHeader(), new GridFieldDataColumns(), new GridFieldPaginator(self::config()->page_length), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm()); $gridField = GridField::create('CloudinaryFile', $title, $this->getList(), $gridFieldConfig); $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); $columns->setDisplayFields(array('StripThumbnail' => '', 'NameForSummaryField' => _t('File.Name'), 'Created' => _t('AssetAdmin.CREATED', 'Date'), 'getSize' => _t('AssetAdmin.SIZE', 'Size'))); $columns->setFieldCasting(array('Created' => 'Date->Nice')); $gridField->setAttribute('data-url-folder-template', Controller::join_links($this->Link('show'), '%s')); if (!$fields->hasTabset()) { $tabs = new TabSet('Root', $tabList = new Tab('ListView', _t('AssetAdmin.ListView', 'List View'))); $tabList->addExtraClass("content-listview cms-tabset-icon list"); $fields->push($tabs); } $uploadBtn = new LiteralField('UploadButton', sprintf('<a class="ss-ui-button ss-ui-action-constructive cms-panel-link" data-pjax-target="Content" data-icon="drive-upload" href="%s">%s</a>', Controller::join_links(singleton('CloudinaryFileAddController')->Link()), _t('Folder.UploadFilesButton', 'Upload'))); $actionButtonsComposite = CompositeField::create()->addExtraClass('cms-actions-row'); $actionButtonsComposite->push($uploadBtn); $fields->addFieldsToTab('Root.ListView', array($actionsComposite = CompositeField::create($actionButtonsComposite)->addExtraClass('cms-content-toolbar field'), $gridField)); $fields->setForm($form); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); $form->addExtraClass('cms-edit-form center ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $this->extend('updateEditForm', $form); return $form; }
public function getEditForm($id = null, $fields = null) { $form = parent::getEditForm(); $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); $fields = $form->Fields(); $this->createFields($fields); $fields->setForm($form); return $form; }
public function getEditForm($id = null, $field = null) { $form = parent::getEditForm($id, $field); $form->addExtraClass("center"); // Setup Fields $form->setFields($this->facebook->getCMSFields()); // Setup Actions $form->setActions($this->getCMSActions()); // Populate Form $form->loadDataFrom($this->facebook); 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 GridFieldExportButton()))->addExtraClass("members_grid"); $memberListConfig->getComponentByType('GridFieldDetailForm')->setValidator(new Member_Validator()); $groupList = GridField::create('Groups', false, Group::get(), GridFieldConfig_RecordEditor::create()); $columns = $groupList->getConfig()->getComponentByType('GridFieldDataColumns'); $columns->setDisplayFields(array('Breadcrumbs' => singleton('Group')->fieldLabel('Title'))); $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'))), new HeaderField(_t('SecurityAdmin.IMPORTUSERS', 'Import users'), 3), new LiteralField('MemberImportFormIframe', sprintf('<iframe src="%s" id="MemberImportFormIframe" width="100%%" height="250px" border="0">' . '</iframe>', $this->Link('memberimport')))), $groupsTab = new Tab('Groups', singleton('Group')->i18n_plural_name(), $groupList, new HeaderField(_t('SecurityAdmin.IMPORTGROUPS', 'Import groups'), 3), new LiteralField('GroupImportFormIframe', sprintf('<iframe src="%s" id="GroupImportFormIframe" width="100%%" height="250px" border="0">' . '</iframe>', $this->Link('groupimport'))))), new HiddenField('ID', false, 0)); $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->request->param('Action'); if ($actionParam == 'groups') { $groupsTab->addExtraClass('ui-state-selected'); } elseif ($actionParam == 'users') { $usersTab->addExtraClass('ui-state-selected'); } elseif ($actionParam == 'roles') { $rolesTab->addExtraClass('ui-state-selected'); } $actions = new FieldList(); $form = new Form($this, 'EditForm', $fields, $actions); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); 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) { $this->setCurrentPageID(Member::currentUserID()); $form = parent::getEditForm($id, $fields); if ($form instanceof SS_HTTPResponse) { return $form; } $form->Fields()->removeByName('LastVisited'); $form->Fields()->push(new HiddenField('ID', null, Member::currentUserID())); $form->Actions()->push(FormAction::create('save', _t('CMSMain.SAVE', 'Save'))->addExtraClass('ss-ui-button ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true)); $form->Actions()->removeByName('action_delete'); if ($member = Member::currentUser()) { $form->setValidator($member->getValidator()); } else { $form->setValidator(Injector::inst()->get('Member')->getValidator()); } if ($form->Fields()->hasTabset()) { $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); } $form->addExtraClass('member-profile-form root-form cms-edit-form center'); return $form; }
/** * Calls {@link SiteTree->getCMSFields()} */ public function getEditForm($id = null) { // Include JavaScript to ensure HtmlEditorField works. HtmlEditorField::include_js(); $form = parent::getEditForm($id); // TODO Duplicate record fetching (see parent implementation) if (!$id) { $id = $this->currentPageID(); } $record = $id && $id != "root" ? $this->getRecord($id) : null; $fields = $form->Fields(); $actions = $form->Actions(); if ($record) { $fields->push($idField = new HiddenField("ID", false, $id)); // Necessary for different subsites $fields->push($liveURLField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink())); $fields->push($liveURLField = new HiddenField("LiveURLSegment")); $fields->push($stageURLField = new HiddenField("StageURLSegment")); $fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle)); $fields->push(new HiddenField('Sort', '', $record->Sort)); if ($record->ID && is_numeric($record->ID)) { $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".\"ID\" = {$record->ID}"); if ($liveRecord) { $liveURLField->setValue($liveRecord->AbsoluteLink()); } } if (!$record->IsDeletedFromStage) { $stageURLField->setValue($record->AbsoluteLink()); } // getAllCMSActions can be used to completely redefine the action list if ($record->hasMethod('getAllCMSActions')) { $actions = $record->getAllCMSActions(); } else { $actions = $record->getCMSActions(); } // Add a default or custom validator. // @todo Currently the default Validator.js implementation // adds javascript to the document body, meaning it won't // be included properly if the associated fields are loaded // through ajax. This means only serverside validation // will kick in for pages+validation loaded through ajax. // This will be solved by using less obtrusive javascript validation // in the future, see http://open.silverstripe.com/ticket/2915 and http://open.silverstripe.com/ticket/3386 if ($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); } else { $validator = new RequiredFields(); } // The clientside (mainly LeftAndMain*.js) rely on ajax responses // which can be evaluated as javascript, hence we need // to override any global changes to the validation handler. $validator->setJavascriptValidationHandler('prototype'); $form = new Form($this, "EditForm", $fields, $actions, $validator); $form->loadDataFrom($record); $form->disableDefaultAction(); if (!$record->canEdit() || $record->IsDeletedFromStage) { $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); } $this->extend('updateEditForm', $form); return $form; } if ($id == 0 || $id == 'root') { return $this->RootForm(); } else { if ($id) { return new Form($this, "EditForm", new FieldSet(new LabelField('PageDoesntExistLabel', _t('CMSMain.PAGENOTEXISTS', "This page doesn't exist"))), new FieldSet()); } } }
/** * @param Int $id * @param FieldList $fields * @return Form */ public function getEditForm($id = null, $fields = null) { 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); } if (!$fields) { $fields = $form->Fields(); } $actions = $form->Actions(); if ($record) { $deletedFromStage = $record->IsDeletedFromStage; $deleteFromLive = !$record->ExistsOnLive; $fields->push($idField = new HiddenField("ID", false, $id)); // Necessary for different subsites $fields->push($liveLinkField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink())); $fields->push($liveLinkField = new HiddenField("LiveLink")); $fields->push($stageLinkField = new HiddenField("StageLink")); $fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle)); if ($record->ID && is_numeric($record->ID)) { $liveLink = $record->getAbsoluteLiveLink(); if ($liveLink) { $liveLinkField->setValue($liveLink); } if (!$deletedFromStage) { $stageLink = Controller::join_links($record->AbsoluteLink(), '?stage=Stage'); if ($stageLink) { $stageLinkField->setValue($stageLink); } } } // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load if (in_array('CMSPreviewable', class_implements($record)) && !$fields->fieldByName('SilverStripeNavigator')) { $navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()); $navField->setAllowHTML(true); $fields->push($navField); } // getAllCMSActions can be used to completely redefine the action list if ($record->hasMethod('getAllCMSActions')) { $actions = $record->getAllCMSActions(); } else { $actions = $record->getCMSActions(); // Find and remove action menus that have no actions. if ($actions && $actions->Count()) { $tabset = $actions->fieldByName('ActionMenus'); if ($tabset) { foreach ($tabset->getChildren() as $tab) { if (!$tab->getChildren()->count()) { $tabset->removeByName($tab->getName()); } } } } } // Use <button> to allow full jQuery UI styling $actionsFlattened = $actions->dataFields(); if ($actionsFlattened) { foreach ($actionsFlattened as $action) { $action->setUseButtonTag(true); } } if ($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); } else { $validator = new RequiredFields(); } $form = CMSForm::create($this, "EditForm", $fields, $actions, $validator)->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); $form->loadDataFrom($record); $form->disableDefaultAction(); $form->addExtraClass('cms-edit-form'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('center ' . $this->BaseCSSClasses()); // if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); // Set validation exemptions for specific actions $form->setValidationExemptActions(array('restore', 'revert', 'deletefromlive', 'rollback')); // Announce the capability so the frontend can decide whether to allow preview or not. if (in_array('CMSPreviewable', class_implements($record))) { $form->addExtraClass('cms-previewable'); } if (!$record->canEdit() || $deletedFromStage) { $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); } $this->extend('updateEditForm', $form); return $form; } else { if ($id) { $form = CMSForm::create($this, "EditForm", new FieldList(new LabelField('PageDoesntExistLabel', _t('CMSMain.PAGENOTEXISTS', "This page doesn't exist"))), new FieldList())->setHTMLID('Form_EditForm'); $form->setResponseNegotiator($this->getResponseNegotiator()); 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(); } $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; }
/** * Calls {@link SiteTree->getCMSFields()} */ public function getEditForm($id = null) { // Include JavaScript to ensure HtmlEditorField works. HtmlEditorField::include_js(); $form = parent::getEditForm($id); // TODO Duplicate record fetching (see parent implementation) if (!$id) { $id = $this->currentPageID(); } $record = $id && $id != "root" ? $this->getRecord($id) : null; $fields = $form->Fields(); $actions = $form->Actions(); if ($record) { $fields->push($idField = new HiddenField("ID", false, $id)); // Necessary for different subsites $fields->push($liveURLField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink())); $fields->push($liveURLField = new HiddenField("LiveURLSegment")); $fields->push($stageURLField = new HiddenField("StageURLSegment")); $fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle)); $fields->push(new HiddenField('Sort', '', $record->Sort)); if ($record->ID && is_numeric($record->ID)) { $liveRecord = Versioned::get_one_by_stage('SiteTree', 'Live', "\"SiteTree\".\"ID\" = {$record->ID}"); if ($liveRecord) { $liveURLField->setValue($liveRecord->AbsoluteLink()); } } if (!$record->IsDeletedFromStage) { $stageURLField->setValue($record->AbsoluteLink()); } $deleteAction = new FormAction('delete', _t('CMSMain.DELETE', 'Delete from the draft site')); $deleteAction->addExtraClass('delete'); $actions->insertBefore($deleteAction, 'action_save'); if ($record->IsDeletedFromStage) { $form->makeReadonly(); } } elseif ($id == 0) { $siteConfig = SiteConfig::current_site_config(); $fields = $siteConfig->getCMSFields(); if (Object::has_extension('SiteConfig', "Translatable")) { $fields->push(new HiddenField('Locale', '', $siteConfig->Locale)); } $form = new Form($this, "EditForm", $fields, $siteConfig->getCMSActions()); $form->loadDataFrom($siteConfig); return $form; } else { $form = $this->EmptyForm(); } 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; }
public function getEditForm($id = null, $fields = null) { Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js'); Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css'); $form = parent::getEditForm($id, $fields); $folder = $id && is_numeric($id) ? DataObject::get_by_id('Folder', $id, false) : $this->currentPage(); $fields = $form->Fields(); $title = $folder && $folder->exists() ? $folder->Title : _t('AssetAdmin.FILES', 'Files'); $fields->push(new HiddenField('ID', false, $folder ? $folder->ID : null)); // File listing $gridFieldConfig = GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldSortableHeader(), new GridFieldFilterHeader(), new GridFieldDataColumns(), new GridFieldPaginator(self::config()->page_length), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm(), GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d')); $gridField = GridField::create('File', $title, $this->getList(), $gridFieldConfig); $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); $columns->setDisplayFields(array('StripThumbnail' => '', 'Title' => _t('File.Title', 'Title'), 'Created' => _t('AssetAdmin.CREATED', 'Date'), 'Size' => _t('AssetAdmin.SIZE', 'Size'))); $columns->setFieldCasting(array('Created' => 'SS_Datetime->Nice')); $gridField->setAttribute('data-url-folder-template', Controller::join_links($this->Link('show'), '%s')); if (!$folder->hasMethod('canAddChildren') || $folder->hasMethod('canAddChildren') && $folder->canAddChildren()) { // TODO Will most likely be replaced by GridField logic $addFolderBtn = new LiteralField('AddFolderButton', sprintf('<a class="ss-ui-button font-icon-folder-add no-text cms-add-folder-link" title="%s" data-icon="add" data-url="%s" href="%s"></a>', _t('Folder.AddFolderButton', 'Add folder'), Controller::join_links($this->Link('AddForm'), '?' . http_build_query(array('action_doAdd' => 1, 'ParentID' => $folder->ID, 'SecurityID' => $form->getSecurityToken()->getValue()))), Controller::join_links($this->Link('addfolder'), '?ParentID=' . $folder->ID))); } else { $addFolderBtn = ''; } // Move existing fields to a "details" tab, unless they've already been tabbed out through extensions. // Required to keep Folder->getCMSFields() simple and reuseable, // without any dependencies into AssetAdmin (e.g. useful for "add folder" views). if (!$fields->hasTabset()) { $tabs = new TabSet('Root', $tabList = new Tab('ListView', _t('AssetAdmin.ListView', 'List View')), $tabTree = new Tab('TreeView', _t('AssetAdmin.TreeView', 'Tree View'))); $tabList->addExtraClass("content-listview cms-tabset-icon list"); $tabTree->addExtraClass("content-treeview cms-tabset-icon tree"); if ($fields->Count() && $folder->exists()) { $tabs->push($tabDetails = new Tab('DetailsView', _t('AssetAdmin.DetailsView', 'Details'))); $tabDetails->addExtraClass("content-galleryview cms-tabset-icon edit"); foreach ($fields as $field) { $fields->removeByName($field->getName()); $tabDetails->push($field); } } $fields->push($tabs); } // we only add buttons if they're available. User might not have permission and therefore // the button shouldn't be available. Adding empty values into a ComposteField breaks template rendering. $actionButtonsComposite = CompositeField::create()->addExtraClass('cms-actions-row'); if ($addFolderBtn) { $actionButtonsComposite->push($addFolderBtn); } // Add the upload field for new media if ($currentPageID = $this->currentPageID()) { Session::set("{$this->class}.currentPage", $currentPageID); } $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()) { $path = $folder->getFilename(); $uploadField->setFolderName($path); } else { $uploadField->setFolderName('/'); // root of the assets } $exts = $uploadField->getValidator()->getAllowedExtensions(); asort($exts); $uploadField->Extensions = implode(', ', $exts); // List view $fields->addFieldsToTab('Root.ListView', array($actionsComposite = CompositeField::create($actionButtonsComposite)->addExtraClass('cms-content-toolbar field'), $uploadField, new HiddenField('ID'), $gridField)); // Tree view $fields->addFieldsToTab('Root.TreeView', array(clone $actionsComposite, new LiteralField('Tree', FormField::create_tag('div', array('class' => 'cms-tree', 'data-url-tree' => $this->Link('getsubtree'), 'data-url-savetreenode' => $this->Link('savetreenode')), $this->SiteTreeAsUL())))); // Move actions to "details" tab (they don't make sense on list/tree view) $actions = $form->Actions(); $saveBtn = $actions->fieldByName('action_save'); $deleteBtn = $actions->fieldByName('action_delete'); $actions->removeByName('action_save'); $actions->removeByName('action_delete'); if (($saveBtn || $deleteBtn) && $fields->fieldByName('Root.DetailsView')) { $fields->addFieldToTab('Root.DetailsView', CompositeField::create($saveBtn, $deleteBtn)->addExtraClass('Actions')); } $fields->setForm($form); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('cms-edit-form ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $this->extend('updateEditForm', $form); return $form; }
public function getEditForm($id = null, $fields = null) { $form = parent::getEditForm($id, $fields); $folder = $id && is_numeric($id) ? DataObject::get_by_id('Folder', $id, false) : $this->currentPage(); $fields = $form->Fields(); $title = $folder && $folder->exists() ? $folder->Title : _t('AssetAdmin.FILES', 'Files'); $fields->push(new HiddenField('ID', false, $folder ? $folder->ID : null)); // File listing $gridFieldConfig = GridFieldConfig::create()->addComponents(new GridFieldToolbarHeader(), new GridFieldSortableHeader(), new GridFieldFilterHeader(), new GridFieldDataColumns(), new GridFieldPaginator(self::config()->page_length), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm(), GridFieldLevelup::create($folder->ID)->setLinkSpec('admin/assets/show/%d')); $gridField = GridField::create('File', $title, $this->getList(), $gridFieldConfig); $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); $columns->setDisplayFields(array('StripThumbnail' => '', 'Title' => _t('File.Title', 'Title'), 'Created' => _t('AssetAdmin.CREATED', 'Date'), 'Size' => _t('AssetAdmin.SIZE', 'Size'))); $columns->setFieldCasting(array('Created' => 'SS_Datetime->Nice')); $gridField->setAttribute('data-url-folder-template', Controller::join_links($this->Link('show'), '%s')); if ($folder->canCreate()) { $uploadBtn = new LiteralField('UploadButton', sprintf('<a class="ss-ui-button ss-ui-action-constructive cms-panel-link" data-pjax-target="Content" data-icon="drive-upload" href="%s">%s</a>', Controller::join_links(singleton('CMSFileAddController')->Link(), '?ID=' . $folder->ID), _t('Folder.UploadFilesButton', 'Upload'))); } else { $uploadBtn = null; } if (!$folder->hasMethod('canAddChildren') || $folder->hasMethod('canAddChildren') && $folder->canAddChildren()) { // TODO Will most likely be replaced by GridField logic $addFolderBtn = new LiteralField('AddFolderButton', sprintf('<a class="ss-ui-button ss-ui-action-constructive cms-add-folder-link" data-icon="add" data-url="%s" href="%s">%s</a>', Controller::join_links($this->Link('AddForm'), '?' . http_build_query(array('action_doAdd' => 1, 'ParentID' => $folder->ID, 'SecurityID' => $form->getSecurityToken()->getValue()))), Controller::join_links($this->Link('addfolder'), '?ParentID=' . $folder->ID), _t('Folder.AddFolderButton', 'Add folder'))); } else { $addFolderBtn = ''; } if ($folder->canEdit()) { $syncButton = new LiteralField('SyncButton', sprintf('<a class="ss-ui-button ss-ui-action ui-button-text-icon-primary ss-ui-button-ajax" data-icon="arrow-circle-double" title="%s" href="%s">%s</a>', _t('AssetAdmin.FILESYSTEMSYNCTITLE', 'Update the CMS database entries of files on the filesystem. Useful when new files have been uploaded outside of the CMS, e.g. through FTP.'), $this->Link('doSync'), _t('AssetAdmin.FILESYSTEMSYNC', 'Sync files'))); } else { $syncButton = null; } // Move existing fields to a "details" tab, unless they've already been tabbed out through extensions. // Required to keep Folder->getCMSFields() simple and reuseable, // without any dependencies into AssetAdmin (e.g. useful for "add folder" views). if (!$fields->hasTabset()) { $tabs = new TabSet('Root', $tabList = new Tab('ListView', _t('AssetAdmin.ListView', 'List View')), $tabTree = new Tab('TreeView', _t('AssetAdmin.TreeView', 'Tree View'))); $tabList->addExtraClass("content-listview cms-tabset-icon list"); $tabTree->addExtraClass("content-treeview cms-tabset-icon tree"); if ($fields->Count() && $folder->exists()) { $tabs->push($tabDetails = new Tab('DetailsView', _t('AssetAdmin.DetailsView', 'Details'))); $tabDetails->addExtraClass("content-galleryview cms-tabset-icon edit"); foreach ($fields as $field) { $fields->removeByName($field->getName()); $tabDetails->push($field); } } $fields->push($tabs); } // we only add buttons if they're available. User might not have permission and therefore // the button shouldn't be available. Adding empty values into a ComposteField breaks template rendering. $actionButtonsComposite = CompositeField::create()->addExtraClass('cms-actions-row'); if ($uploadBtn) { $actionButtonsComposite->push($uploadBtn); } if ($addFolderBtn) { $actionButtonsComposite->push($addFolderBtn); } if ($syncButton) { $actionButtonsComposite->push($syncButton); } // List view $fields->addFieldsToTab('Root.ListView', array($actionsComposite = CompositeField::create($actionButtonsComposite)->addExtraClass('cms-content-toolbar field'), $gridField)); $treeField = new LiteralField('Tree', ''); // Tree view $fields->addFieldsToTab('Root.TreeView', array(clone $actionsComposite, new LiteralField('Tree', FormField::create_tag('div', array('class' => 'cms-tree', 'data-url-tree' => $this->Link('getsubtree'), 'data-url-savetreenode' => $this->Link('savetreenode')), $this->SiteTreeAsUL())))); // Move actions to "details" tab (they don't make sense on list/tree view) $actions = $form->Actions(); $saveBtn = $actions->fieldByName('action_save'); $deleteBtn = $actions->fieldByName('action_delete'); $actions->removeByName('action_save'); $actions->removeByName('action_delete'); if (($saveBtn || $deleteBtn) && $fields->fieldByName('Root.DetailsView')) { $fields->addFieldToTab('Root.DetailsView', CompositeField::create($saveBtn, $deleteBtn)->addExtraClass('Actions')); } $fields->setForm($form); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $this->extend('updateEditForm', $form); return $form; }
/** * @param Int $id * @param FieldList $fields * @return Form */ public function getEditForm($id = null, $fields = null) { 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); } if (!$fields) { $fields = $form->Fields(); } $actions = $form->Actions(); if ($record) { $deletedFromStage = $record->IsDeletedFromStage; $deleteFromLive = !$record->ExistsOnLive; $fields->push($idField = new HiddenField("ID", false, $id)); // Necessary for different subsites $fields->push($liveLinkField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink())); $fields->push($liveLinkField = new HiddenField("LiveLink")); $fields->push($stageLinkField = new HiddenField("StageLink")); if ($record->ID && is_numeric($record->ID)) { $liveLink = $record->getAbsoluteLiveLink(); if ($liveLink) { $liveLinkField->setValue($liveLink); } if (!$deletedFromStage) { $stageLink = Controller::join_links($record->AbsoluteLink(), '?stage=Stage'); if ($stageLink) { $stageLinkField->setValue($stageLink); } } } // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load /*if(in_array('CMSPreviewable', class_implements($record)) && !$fields->fieldByName('SilverStripeNavigator')) { $navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()); $navField->setAllowHTML(true); $fields->push($navField); }*/ // getAllCMSActions can be used to completely redefine the action list if ($record->hasMethod('getAllCMSActions')) { $actions = $record->getAllCMSActions(); } else { $actions = $record->getCMSActions(); } // Use <button> to allow full jQuery UI styling $actionsFlattened = $actions->dataFields(); if ($actionsFlattened) { foreach ($actionsFlattened as $action) { $action->setUseButtonTag(true); } } if ($record->hasMethod('getCMSValidator')) { $validator = $record->getCMSValidator(); } else { $validator = new RequiredFields(); } $form = new Form($this, "EditForm", $fields, $actions, $validator); $form->loadDataFrom($record); $form->disableDefaultAction(); $form->addExtraClass('cms-edit-form content-module'); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('center ' . $this->BaseCSSClasses()); $form->setAttribute('data-pjax-fragment', 'CurrentForm'); if (!$record->canEdit() || $deletedFromStage) { $readonlyFields = $form->Fields()->makeReadonly(); $form->setFields($readonlyFields); } $this->extend('updateEditForm', $form); return $form; } else { if ($id) { return new Form($this, "EditForm", new FieldList(new LabelField('ModuleDoesntExistLabel', _t('ContentModule.MODULENOTEXISTS', "This module doesn't exist"))), new FieldList()); } } return $this->ListViewForm(); }
public function getEditForm($id = null, $fields = null) { $form = parent::getEditForm($id, $fields); $folder = ($id && is_numeric($id)) ? DataObject::get_by_id('Folder', $id, false) : $this->currentPage(); $fields = $form->Fields(); $fields->push(new HiddenField('ID', false, $folder->ID)); // File listing $gridFieldConfig = GridFieldConfig::create()->addComponents( new GridFieldSortableHeader(), new GridFieldDataColumns(), new GridFieldPaginator(15), new GridFieldEditButton(), new GridFieldDeleteAction(), new GridFieldDetailForm() ); $gridField = new GridField('File','Files', $this->getList(), $gridFieldConfig); $columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns'); $columns->setDisplayFields(array( 'StripThumbnail' => '', // 'Parent.FileName' => 'Folder', 'Title' => _t('File.Name'), 'Created' => _t('AssetAdmin.CREATED', 'Date'), 'Size' => _t('AssetAdmin.SIZE', 'Size'), )); $columns->setFieldCasting(array( 'Created' => 'Date->Nice' )); $gridField->setAttribute( 'data-url-folder-template', Controller::join_links($this->Link('show'), '%s') ); if($folder->canCreate()) { $uploadBtn = new LiteralField( 'UploadButton', sprintf( '<a class="ss-ui-button ss-ui-action-constructive cms-panel-link" data-target-panel=".cms-content" data-icon="drive-upload" href="%s">%s</a>', Controller::join_links(singleton('CMSFileAddController')->Link(), '?ID=' . $folder->ID), _t('Folder.UploadFilesButton', 'Upload') ) ); } else { $uploadBtn = null; } if(!$folder->hasMethod('canAddChildren') || ($folder->hasMethod('canAddChildren') && $folder->canAddChildren())) { // TODO Will most likely be replaced by GridField logic $addFolderBtn = new LiteralField( 'AddFolderButton', sprintf( '<a class="ss-ui-button ss-ui-action-constructive cms-add-folder-link" data-icon="add" data-url="%s" href="%s">%s</a>', Controller::join_links($this->Link('AddForm'), '?' . http_build_query(array( 'action_doAdd' => 1, 'ParentID' => $folder->ID, 'SecurityID' => $form->getSecurityToken()->getValue() ))), Controller::join_links($this->Link('addfolder'), '?ParentID=' . $folder->ID), _t('Folder.AddFolderButton', 'Add folder') ) ); } else { $addFolderBtn = ''; } if($folder->canEdit()) { $syncButton = new LiteralField( 'SyncButton', sprintf( '<a class="ss-ui-button ss-ui-action ui-button-text-icon-primary ss-ui-button-ajax" title="%s" href="%s">%s</a>', _t('AssetAdmin.FILESYSTEMSYNCTITLE', 'Update the CMS database entries of files on the filesystem. Useful when new files have been uploaded outside of the CMS, e.g. through FTP.'), $this->Link('doSync'), _t('FILESYSTEMSYNC','Sync files') ) ); } else { $syncButton = null; } // Move existing fields to a "details" tab, unless they've already been tabbed out through extensions. // Required to keep Folder->getCMSFields() simple and reuseable, // without any dependencies into AssetAdmin (e.g. useful for "add folder" views). if(!$fields->hasTabset()) { $tabs = new TabSet('Root', $tabList = new Tab('ListView', _t('AssetAdmin.ListView', 'List View')), $tabTree = new Tab('TreeView', _t('AssetAdmin.TreeView', 'Tree View')) ); $tabList->addExtraClass("content-listview"); $tabTree->addExtraClass("content-treeview"); if($fields->Count() && $folder->exists()) { $tabs->push($tabDetails = new Tab('DetailsView', _t('AssetAdmin.DetailsView', 'Details'))); $tabDetails->addExtraClass("content-galleryview"); foreach($fields as $field) { $fields->removeByName($field->getName()); $tabDetails->push($field); } } $fields->push($tabs); } // List view $fields->addFieldsToTab('Root.ListView', array( $actionsComposite = CompositeField::create( CompositeField::create( $uploadBtn, $addFolderBtn, $syncButton //TODO: add this into a batch actions menu as in https://github.com/silverstripe/silverstripe-design/raw/master/Design/ss3-ui_files-manager-list-view.jpg )->addExtraClass('cms-actions-row') )->addExtraClass('cms-content-toolbar field'), $gridField )); $treeField = new LiteralField('Tree', ''); // Tree view $fields->addFieldsToTab('Root.TreeView', array( clone $actionsComposite, // TODO Replace with lazy loading on client to avoid performance hit of rendering potentially unused views new LiteralField( 'Tree', $treeField->createTag( 'div', array( 'class' => 'cms-tree', 'data-url-tree' => $this->Link('getsubtree'), 'data-url-savetreenode' => $this->Link('savetreenode') ), $this->SiteTreeAsUL() ) ) )); $fields->setForm($form); $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); // TODO Can't merge $FormAttributes in template at the moment $form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses()); $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); $this->extend('updateEditForm', $form); return $form; }