Exemplo n.º 1
0
 /**
  * @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;
 }
 /**
  * @return Form
  */
 function getEditForm($id = null, $fields = null)
 {
     $siteConfig = SiteConfig::current_site_config();
     $fields = $siteConfig->getCMSFields();
     $actions = $siteConfig->getCMSActions();
     $form = new Form($this, 'EditForm', $fields, $actions);
     $form->addExtraClass('root-form');
     $form->addExtraClass('cms-edit-form cms-panel-padded center');
     // don't add data-pjax-fragment=CurrentForm, its added in the content template instead
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
     }
     $form->setHTMLID('Form_EditForm');
     $form->loadDataFrom($siteConfig);
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     // Use <button> to allow full jQuery UI styling
     $actions = $actions->dataFields();
     if ($actions) {
         foreach ($actions as $action) {
             $action->setUseButtonTag(true);
         }
     }
     $this->extend('updateEditForm', $form);
     return $form;
 }
Exemplo n.º 3
0
 /**
  * @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 AddForm()
 {
     $record = $this->currentPage();
     $moduleTypes = array();
     foreach ($this->ModuleTypes() as $type) {
         $html = sprintf('<span class="page-icon class-%s"></span><strong class="title">%s</strong><span class="description">%s</span>', $type->getField('Title'), $type->getField('AddAction'), $type->getField('Description'));
         $moduleTypes[$type->getField('ClassName')] = $html;
     }
     // Ensure generic page type shows on top
     if (isset($moduleTypes['Page'])) {
         $pageTitle = $moduleTypes['Page'];
         $moduleTypes = array_merge(array('Page' => $pageTitle), $moduleTypes);
     }
     $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($typeField = new OptionsetField("ModuleType", sprintf($numericLabelTmpl, 1, _t('ContentModuleMain.ChooseModuleType', 'Choose module type')), $moduleTypes));
     $actions = new FieldList(FormAction::create("doAdd", _t('CMSMain.Create', "Create"))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true));
     $this->extend('updateModuleOptions', $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
  */
 public function AddForm()
 {
     $fields = new FieldList(new LiteralField('SelectFieldType', '<p><strong>Please select a field type to add:</strong></p>'), $df = new DropdownField('ClassName', '', $this->getFieldTypes(), null, null));
     $df->setHasEmptyDefault(true);
     if ($schemaID = (int) $this->request->param('ID')) {
         $fields->push(new HiddenField('SchemaID', '', $schemaID));
     }
     $actions = new FieldList(FormAction::create('doAddField', 'Create')->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'));
     // Add a Cancel link which is a button-like link and link back to one level up.
     $curmbs = $this->Breadcrumbs();
     if ($curmbs && $curmbs->count() >= 2) {
         $one_level_up = $curmbs->offsetGet($curmbs->count() - 2);
         $text = "\n\t\t\t<a class=\"crumb ss-ui-button ss-ui-action-destructive cms-panel-link ui-corner-all\" href=\"" . $one_level_up->Link . "\">\n\t\t\t\tCancel\n\t\t\t</a>";
         $actions->push(new LiteralField('cancelbutton', $text));
     }
     $form = new Form($this, 'AddForm', $fields, $actions);
     $toplevelController = $this->getToplevelController();
     $form->setTemplate('LeftAndMain_EditForm');
     $form->addExtraClass('cms-content cms-edit-form center ss-tabset stacked');
     $form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
     }
     //var_dump($this->popupController); die;
     $parents = $this->popupController->Breadcrumbs(false)->items;
     $form->Backlink = array_pop($parents)->Link;
     return $form;
 }
 public function getEditForm($id = null, $fields = null)
 {
     $classname = $this->modelClass;
     $list = $classname::get();
     $listField = GridField::create($this->sanitiseClassName($this->modelClass), false, $list, $fieldConfig = GridFieldConfig_RecordEditor::create($this->stat('page_length'))->removeComponentsByType('GridFieldFilterHeader'));
     if (!$this->stat('enable_sorting')) {
         $summary_fields = Config::inst()->get($this->modelClass, 'summary_fields');
         $sorting = array();
         foreach ($summary_fields as $col) {
             $sorting[$col] = 'FieldNameNoSorting';
         }
         $fieldConfig->getComponentByType('GridFieldSortableHeader')->setFieldSorting($sorting);
     }
     // Validation
     if (singleton($this->modelClass)->hasMethod('getCMSValidator')) {
         $detailValidator = singleton($this->modelClass)->getCMSValidator();
         $listField->getConfig()->getComponentByType('GridFieldDetailForm')->setValidator($detailValidator);
     }
     $form = new Form($this, 'EditForm', new FieldList($listField), new FieldList());
     $form->addExtraClass('cms-edit-form cms-panel-padded center');
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     $editFormAction = Controller::join_links($this->Link($this->sanitiseClassName($this->modelClass)), 'EditForm');
     $form->setFormAction($editFormAction);
     $form->setAttribute('data-pjax-fragment', 'CurrentForm');
     $this->extend('updateEditForm', $form);
     return $form;
 }
 /**
  * @return Form
  * @todo what template is used here? AssetAdmin_UploadContent.ss doesn't seem to be used anymore
  */
 public function getEditForm($id = null, $fields = null)
 {
     Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js');
     Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css');
     $folder = $this->currentPage();
     $uploadField = UploadField::create('AssetUploadField', '');
     $uploadField->setConfig('previewMaxWidth', 40);
     $uploadField->setConfig('previewMaxHeight', 30);
     $uploadField->addExtraClass('ss-assetuploadfield');
     $uploadField->removeExtraClass('ss-uploadfield');
     $uploadField->setTemplate('AssetUploadField');
     if ($folder->exists() && $folder->getFilename()) {
         // The Upload class expects a folder relative *within* assets/
         $path = preg_replace('/^' . ASSETS_DIR . '\\//', '', $folder->getFilename());
         $uploadField->setFolderName($path);
     } else {
         $uploadField->setFolderName(ASSETS_DIR);
     }
     $exts = $uploadField->getValidator()->getAllowedExtensions();
     asort($exts);
     $form = new Form($this, 'getEditForm', new FieldList($uploadField, new LiteralField('AllowedExtensions', sprintf('<p>%s: %s</p>', _t('AssetAdmin.ALLOWEDEXTS', 'Allowed extensions'), implode('<em>, </em>', $exts))), new HiddenField('ID')), new FieldList());
     $form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses());
     // Don't use AssetAdmin_EditForm, as it assumes a different panel structure
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     $form->Fields()->push(new LiteralField('BackLink', sprintf('<a href="%s" class="backlink ss-ui-button cms-panel-link" data-icon="back">%s</a>', Controller::join_links(singleton('AssetAdmin')->Link('show'), $folder ? $folder->ID : 0), _t('AssetAdmin.BackToFolder', 'Back to folder'))));
     $form->loadDataFrom($folder);
     return $form;
 }
 public function alterCommentForm(Form $form)
 {
     $form->transform(new FoundationFormTransformation());
     $form->setTemplate('FoundationCommentingControllerForm', 'FoundationForm', 'Form');
     $form->addExtraClass('custom');
     if ($form->hasExtension('FormSpamProtectionExtension')) {
         $form->enableSpamProtection();
     }
 }
Exemplo n.º 9
0
 /**
  * Builds an item edit form.  The arguments to getCMSFields() are the popupController and
  * popupFormName, however this is an experimental API and may change.
  * 
  * @todo In the future, we will probably need to come up with a tigher object representing a partially
  * complete controller with gaps for extra functionality.  This, for example, would be a better way
  * of letting Security/login put its log-in form inside a UI specified elsewhere.
  * 
  * @return Form 
  */
 function ItemEditForm()
 {
     if (empty($this->record)) {
         $controller = Controller::curr();
         $noActionURL = $controller->removeAction($_REQUEST['url']);
         $controller->getResponse()->removeHeader('Location');
         //clear the existing redirect
         return $controller->redirect($noActionURL, 302);
     }
     $actions = new FieldList();
     if ($this->record->ID !== 0) {
         $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'));
         $actions->push(FormAction::create('doDelete', _t('GridFieldDetailForm.Delete', 'Delete'))->addExtraClass('ss-ui-action-destructive'));
     } else {
         // adding new record
         //Change the Save label to 'Create'
         $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Create', 'Create'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'add'));
         // Add a Cancel link which is a button-like link and link back to one level up.
         $curmbs = $this->Breadcrumbs();
         if ($curmbs && $curmbs->count() >= 2) {
             $one_level_up = $curmbs->offsetGet($curmbs->count() - 2);
             $cancelText = _t('GridFieldDetailForm.CancelBtn', 'Cancel');
             $text = "\r\n\t\t\t\t<a class=\"crumb ss-ui-button ss-ui-action-destructive cms-panel-link ui-corner-all\" href=\"" . $one_level_up->Link . "\">\r\n\t\t\t\t\t{$cancelText}\r\n\t\t\t\t</a>";
             $actions->push(new LiteralField('cancelbutton', $text));
         }
     }
     $fk = $this->gridField->getList()->foreignKey;
     $this->record->{$fk} = $this->gridField->getList()->foreignID;
     $form = new Form($this, 'ItemEditForm', $this->record->getCMSFields(), $actions, $this->component->getValidator());
     $form->loadDataFrom($this->record);
     // TODO Coupling with CMS
     $toplevelController = $this->getToplevelController();
     if ($toplevelController && $toplevelController instanceof LeftAndMain) {
         // Always show with base template (full width, no other panels),
         // regardless of overloaded CMS controller templates.
         // TODO Allow customization, e.g. to display an edit form alongside a search form from the CMS controller
         $form->setTemplate('LeftAndMain_EditForm');
         $form->addExtraClass('cms-content cms-edit-form center ss-tabset');
         $form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
         if ($form->Fields()->hasTabset()) {
             $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
         }
         if ($toplevelController->hasMethod('Backlink')) {
             $form->Backlink = $toplevelController->Backlink();
         } elseif ($this->popupController->hasMethod('Breadcrumbs')) {
             $parents = $this->popupController->Breadcrumbs(false)->items;
             $form->Backlink = array_pop($parents)->Link;
         } else {
             $form->Backlink = $toplevelController->Link();
         }
     }
     $cb = $this->component->getItemEditFormCallback();
     if ($cb) {
         $cb($form, $this);
     }
     return $form;
 }
 public function alterCommentForm(Form $form)
 {
     $form->Fields()->bootstrapify();
     $form->Actions()->bootstrapify();
     $form->setTemplate('FoundationCommentingControllerForm', 'FoundationForm');
     if ($form->hasExtension('FormSpamProtectionExtension')) {
         $form->enableSpamProtection();
     }
     Requirements::css(FOUNDATIONFORMS_DIR . '/css/foundationforms.css');
 }
 /**
  * This method should be overloaded to build out the detail form.
  *
  * @return Form
  */
 public function Form()
 {
     $form = new Form($this, 'Form', new FieldList($root = new TabSet('Root', new Tab('Main'))), new FieldList());
     if ($this->getTopLevelController() instanceof LeftAndMain) {
         $form->setTemplate('LeftAndMain_EditForm');
         $form->addExtraClass('cms-content cms-edit-form cms-tabset center');
         $form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
         $root->setTemplate('CMSTabSet');
         $form->Backlink = $this->getBackLink();
     }
     return $form;
 }
 /**
  * @param int|null $id
  * @param array|null $fields
  * @return \Form
  */
 public function getEditForm($id = null, $fields = null)
 {
     $queues = $this->getQueues();
     $gridField = new GridField('Queues', 'Queues', $queues, new GridFieldConfig_RecordEditor());
     $dataComponent = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
     $dataComponent->setDisplayFields(array('Name' => 'Name', 'Size' => 'Size'));
     $form = new Form($this, 'EditForm', new FieldList($gridField), new FieldList());
     $form->addExtraClass('cms-edit-form cms-panel-padded center');
     $form->setAttribute('data-pjax-fragment', 'CurrentForm');
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     $form->setAttribute('data-pjax-fragment', 'CurrentForm');
     return $form;
 }
Exemplo n.º 13
0
 /**
  * Get search form
  *
  * @return Form
  */
 public function BlogSearchForm()
 {
     $searchField = TextField::create('Keyword', false)->setAttribute('placeholder', 'Type to search')->setAttribute('type', 'search');
     $keyword = Controller::curr()->request->getVar('Search');
     if ($keyword) {
         $searchField->setValue($keyword);
     }
     $fields = new FieldList($searchField);
     $formAction = FormAction::create('doSearch');
     $formAction->useButtonTag = true;
     $formAction->setButtonContent('<span class="fa fa-search"></span>');
     $actions = new FieldList($formAction);
     $form = new Form($this, 'BlogSearchForm', $fields, $actions);
     $form->setAttribute('role', 'search');
     $form->setTemplate('BlogSearchForm');
     return $form;
 }
 public function updateProfileForm(Form $form)
 {
     if (!Config::inst()->get('BootstrapForm', 'bootstrap_included')) {
         Requirements::css(BOOTSTRAP_FORMS_DIR . '/css/bootstrap.css');
     }
     if (!Config::inst()->get('BootstrapForm', 'jquery_included')) {
         Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
     }
     if (!Config::inst()->get('BootstrapForm', 'bootstrap_form_included')) {
         Requirements::javascript(BOOTSTRAP_FORMS_DIR . "/javascript/bootstrap_forms.js");
     }
     $form->Fields()->bootstrapify();
     $form->Actions()->bootstrapify();
     $form->addExtraClass('well');
     $form->addExtraClass('form-horizontal');
     $form->setTemplate('BootstrapForm');
 }
Exemplo n.º 15
0
 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;
 }
Exemplo n.º 16
0
 function ContactForm()
 {
     // Set up the fields
     $nameField = new TextField('Name', 'Name');
     $nameField->setAttribute('placeholder', 'Name');
     $emailField = new EmailField('Email', 'Email');
     $emailField->setAttribute('placeholder', 'Email');
     $messageField = new TextareaField('Message', 'Message');
     $messageField->setAttribute('placeholder', 'Message');
     // Add the fields
     $fields = new FieldList($nameField, $emailField, $messageField);
     // Create action
     $actions = new FieldList(new FormAction('SendContactForm', 'Send Message'));
     // Create Validators
     $validator = new RequiredFields('Name', 'Email', 'Message');
     // Set up the form
     $form = new Form($this, 'ContactForm', $fields, $actions, $validator);
     $form->setTemplate('ContactForm');
     return $form;
 }
 /**
  * @return Form
  * @todo what template is used here? AssetAdmin_UploadContent.ss doesn't seem to be used anymore
  */
 public function getEditForm($id = null, $fields = null)
 {
     Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js');
     Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css');
     Requirements::css(DMS_DIR . '/css/DMSMainCMS.css');
     $page = $this->currentPage();
     $uploadField = DMSUploadField::create('AssetUploadField', '');
     $uploadField->setConfig('previewMaxWidth', 40);
     $uploadField->setConfig('previewMaxHeight', 30);
     // Required to avoid Solr reindexing (often used alongside DMS) to
     // return 503s because of too many concurrent reindex requests
     $uploadField->setConfig('sequentialUploads', 1);
     $uploadField->addExtraClass('ss-assetuploadfield');
     $uploadField->removeExtraClass('ss-uploadfield');
     $uploadField->setTemplate('AssetUploadField');
     $uploadField->setRecord($page);
     $uploadField->getValidator()->setAllowedExtensions(array_filter(array_merge(Config::inst()->get('File', 'allowed_extensions'), self::$allowed_extensions)));
     $exts = $uploadField->getValidator()->getAllowedExtensions();
     asort($exts);
     $backlink = $this->Backlink();
     $done = "\n\t\t<a class=\"ss-ui-button ss-ui-action-constructive cms-panel-link ui-corner-all\" href=\"" . $backlink . "\">\n\t\t\tDone!\n\t\t</a>";
     $addExistingField = new DMSDocumentAddExistingField('AddExisting', 'Add Existing');
     $addExistingField->setRecord($page);
     $form = new Form($this, 'getEditForm', new FieldList(new TabSet('Main', new Tab('From your computer', new HiddenField('ID', false, $page->ID), $uploadField, new LiteralField('AllowedExtensions', sprintf('<p>%s: %s</p>', _t('AssetAdmin.ALLOWEDEXTS', 'Allowed extensions'), implode('<em>, </em>', $exts)))), new Tab('From the CMS', $addExistingField))), new FieldList(new LiteralField('doneButton', $done)));
     $form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses());
     $form->Backlink = $backlink;
     // Don't use AssetAdmin_EditForm, as it assumes a different panel structure
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     /*$form->Fields()->push(
     			new LiteralField(
     				'BackLink',
     				sprintf(
     					'<a href="%s" class="backlink ss-ui-button cms-panel-link" data-icon="back">%s</a>',
     					Controller::join_links(singleton('AssetAdmin')->Link('show'), $folder ? $folder->ID : 0),
     					_t('AssetAdmin.BackToFolder', 'Back to folder')
     				)
     			)
     		);*/
     //$form->loadDataFrom($folder);
     return $form;
 }
 public function OrderForm($id = null)
 {
     $product = empty($id) ? new Product() : DataObject::get_one('Product', array('ID' => (int) $id));
     try {
         $processor = PaymentFactory::factory($this->paymentMethod);
     } catch (Exception $e) {
         $fields = new FieldList(array(new ReadonlyField($e->getMessage())));
         $actions = new FieldList();
         return new Form($this, 'OrderForm', $fields, $actions);
     }
     $fields = new FieldList();
     $fields->push(new HiddenField('Amount', 'Amount', $product->Price));
     $fields->push(new HiddenField('Currency', 'Currency', 'NZD'));
     $fields->push(new HiddenField('PaymentMethod', 'PaymentMethod', 'PayPalExpress'));
     $actions = new FieldList($button = new FormAction('processOrder', 'Buy Now'));
     $button->addExtraClass('button expand');
     $validator = $processor->getFormRequirements();
     $form = new Form($this, "OrderForm", $fields, $actions, $validator);
     $form->setTemplate('OrderForm');
     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 getEditForm($id = null, $fields = null) {
		$siteConfig = SiteConfig::current_site_config();
		$fields = $siteConfig->getCMSFields();

		$actions = $siteConfig->getCMSActions();
		$form = new Form($this, 'EditForm', $fields, $actions);
		$form->addExtraClass('root-form');
		$form->addExtraClass('cms-edit-form');
		// TODO Can't merge $FormAttributes in template at the moment
		$form->addExtraClass('cms-content center ss-tabset');
		if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
		$form->setHTMLID('Form_EditForm');
		$form->loadDataFrom($siteConfig);
		$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));

		// Use <button> to allow full jQuery UI styling
		$actions = $actions->dataFields();
		if($actions) foreach($actions as $action) $action->setUseButtonTag(true);

		$this->extend('updateEditForm', $form);

		return $form;
	}
Exemplo n.º 21
0
 public function getEditForm($id = null, $fields = null)
 {
     $list = $this->getList();
     $exportButton = new GridFieldExportButton('before');
     $exportButton->setExportColumns($this->getExportFields());
     $listField = GridField::create($this->sanitiseClassName($this->modelClass), false, $list, $fieldConfig = GridFieldConfig_RecordEditor::create($this->stat('page_length'))->addComponent($exportButton)->removeComponentsByType('GridFieldFilterHeader')->addComponents(new GridFieldPrintButton('before')));
     // Validation
     if (singleton($this->modelClass)->hasMethod('getCMSValidator')) {
         $detailValidator = singleton($this->modelClass)->getCMSValidator();
         $listField->getConfig()->getComponentByType('GridFieldDetailForm')->setValidator($detailValidator);
     }
     $form = new Form($this, 'EditForm', new FieldList($listField), new FieldList());
     $form->addExtraClass('cms-edit-form cms-panel-padded center');
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     $editFormAction = Controller::join_links($this->Link($this->sanitiseClassName($this->modelClass)), 'EditForm');
     $form->setFormAction($editFormAction);
     $form->setAttribute('data-pjax-fragment', 'CurrentForm');
     $this->extend('updateEditForm', $form);
     return $form;
 }
 /**
  * Return the linked file view form, which shows a readonly form that contains the
  * source text of the file being viewed.
  * @throws Exception
  * @return Form
  */
 public function LinkedFileViewForm()
 {
     // grab the parameters
     if (isset($_REQUEST['ID'])) {
         $id = addslashes($_REQUEST['ID']);
     } else {
         throw new Exception("invalid ID");
     }
     // Extract parameters from this ID. It's base 64 of
     // templateID:path
     $id = base64_decode($id);
     $params = explode(':', $id);
     if (count($params) != 2) {
         throw Exception("Invalid params, expected 2 components");
     }
     $dynamicTemplateId = $params[0];
     $path = $params[1];
     $form = new Form($this, "LinkedFileViewForm", new FieldList(new LabelField("Filename", "File: " . $path), $sourceTextField = new TextareaField("SourceText", ""), new HiddenField('ID', 'ID'), new HiddenField('BackURL', 'BackURL', $this->Link())), new FieldList(new FormAction('cancelFileEdit', _t('DynamicTemplate.CANCELFILEEDIT', 'Cancel'))));
     $form->setTemplate('FilesEditorForm');
     // Get the contents of the file
     $contents = file_get_contents(BASE_PATH . $path);
     $sourceTextField->setRows(20);
     $sourceTextField->setColumns(150);
     $sourceTextField->setValue($contents);
     $form->HelpType = null;
     return $form;
 }
Exemplo n.º 23
0
 /**
  * Builds an item edit form.  The arguments to getCMSFields() are the popupController and
  * popupFormName, however this is an experimental API and may change.
  * 
  * @todo In the future, we will probably need to come up with a tigher object representing a partially
  * complete controller with gaps for extra functionality.  This, for example, would be a better way
  * of letting Security/login put its log-in form inside a UI specified elsewhere.
  * 
  * @return Form 
  */
 public function ItemEditForm()
 {
     $list = $this->gridField->getList();
     if (empty($this->record)) {
         $controller = $this->getToplevelController();
         $noActionURL = $controller->removeAction($_REQUEST['url']);
         $controller->getResponse()->removeHeader('Location');
         //clear the existing redirect
         return $controller->redirect($noActionURL, 302);
     }
     $canView = $this->record->canView();
     $canEdit = $this->record->canEdit();
     $canDelete = $this->record->canDelete();
     $canCreate = $this->record->canCreate();
     if (!$canView) {
         $controller = $this->getToplevelController();
         // TODO More friendly error
         return $controller->httpError(403);
     }
     $actions = new FieldList();
     if ($this->record->ID !== 0) {
         if ($canEdit) {
             $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'));
         }
         if ($canDelete) {
             $actions->push(FormAction::create('doDelete', _t('GridFieldDetailForm.Delete', 'Delete'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-destructive action-delete'));
         }
     } else {
         // adding new record
         //Change the Save label to 'Create'
         $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Create', 'Create'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'add'));
         // Add a Cancel link which is a button-like link and link back to one level up.
         $curmbs = $this->Breadcrumbs();
         if ($curmbs && $curmbs->count() >= 2) {
             $one_level_up = $curmbs->offsetGet($curmbs->count() - 2);
             $text = sprintf("<a class=\"%s\" href=\"%s\">%s</a>", "crumb ss-ui-button ss-ui-action-destructive cms-panel-link ui-corner-all", $one_level_up->Link, _t('GridFieldDetailForm.CancelBtn', 'Cancel'));
             $actions->push(new LiteralField('cancelbutton', $text));
         }
     }
     $fields = $this->component->getFields();
     if (!$fields) {
         $fields = $this->record->getCMSFields();
     }
     // If we are creating a new record in a has-many list, then
     // pre-populate the record's foreign key. Also disable the form field as
     // it has no effect.
     if ($list instanceof HasManyList) {
         $key = $list->getForeignKey();
         $id = $list->getForeignID();
         if (!$this->record->isInDB()) {
             $this->record->{$key} = $id;
         }
         if ($field = $fields->dataFieldByName($key)) {
             $fields->makeFieldReadonly($field);
         }
     }
     // Caution: API violation. Form expects a Controller, but we are giving it a RequestHandler instead.
     // Thanks to this however, we are able to nest GridFields, and also access the initial Controller by
     // dereferencing GridFieldDetailForm_ItemRequest->getController() multiple times. See getToplevelController
     // below.
     $form = new Form($this, 'ItemEditForm', $fields, $actions, $this->component->getValidator());
     $form->loadDataFrom($this->record, $this->record->ID == 0 ? Form::MERGE_IGNORE_FALSEISH : Form::MERGE_DEFAULT);
     if ($this->record->ID && !$canEdit) {
         // Restrict editing of existing records
         $form->makeReadonly();
         // Hack to re-enable delete button if user can delete
         if ($canDelete) {
             $form->Actions()->fieldByName('action_doDelete')->setReadonly(false);
         }
     } elseif (!$this->record->ID && !$canCreate) {
         // Restrict creation of new records
         $form->makeReadonly();
     }
     // Load many_many extraData for record.
     // Fields with the correct 'ManyMany' namespace need to be added manually through getCMSFields().
     if ($list instanceof ManyManyList) {
         $extraData = $list->getExtraData('', $this->record->ID);
         $form->loadDataFrom(array('ManyMany' => $extraData));
     }
     // TODO Coupling with CMS
     $toplevelController = $this->getToplevelController();
     if ($toplevelController && $toplevelController instanceof LeftAndMain) {
         // Always show with base template (full width, no other panels),
         // regardless of overloaded CMS controller templates.
         // TODO Allow customization, e.g. to display an edit form alongside a search form from the CMS controller
         $form->setTemplate('LeftAndMain_EditForm');
         $form->addExtraClass('cms-content cms-edit-form center');
         $form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
         if ($form->Fields()->hasTabset()) {
             $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
             $form->addExtraClass('cms-tabset');
         }
         $form->Backlink = $this->getBackLink();
     }
     $cb = $this->component->getItemEditFormCallback();
     if ($cb) {
         $cb($form, $this);
     }
     $this->extend("updateItemEditForm", $form);
     return $form;
 }
 /**
  * Return the form for editing
  */
 function getEditForm($id = null, $fields = null)
 {
     $record = null;
     if (!$id) {
         $id = $this->getCurrentPageID();
     }
     if ($id && $id != "root") {
         $record = $this->getRecord($id);
     }
     if ($record) {
         $fields = $record->getCMSFields();
         // If we're editing an external source or item, and it can be imported
         // then add the "Import" tab.
         $isSource = $record instanceof ExternalContentSource;
         $isItem = $record instanceof ExternalContentItem;
         if (($isSource || $isItem) && $record->canImport()) {
             $allowedTypes = $record->allowedImportTargets();
             if (isset($allowedTypes['sitetree'])) {
                 $fields->addFieldToTab('Root.Import', new TreeDropdownField("MigrationTarget", _t('ExternalContent.MIGRATE_TARGET', 'Page to import into'), 'SiteTree'));
             }
             if (isset($allowedTypes['file'])) {
                 $fields->addFieldToTab('Root.Import', new TreeDropdownField("FileMigrationTarget", _t('ExternalContent.FILE_MIGRATE_TARGET', 'Folder to import into'), 'Folder'));
             }
             $fields->addFieldToTab('Root.Import', new CheckboxField("IncludeSelected", _t('ExternalContent.INCLUDE_SELECTED', 'Include Selected Item in Import')));
             $fields->addFieldToTab('Root.Import', new CheckboxField("IncludeChildren", _t('ExternalContent.INCLUDE_CHILDREN', 'Include Child Items in Import'), true));
             $duplicateOptions = array(ExternalContentTransformer::DS_OVERWRITE => ExternalContentTransformer::DS_OVERWRITE, ExternalContentTransformer::DS_DUPLICATE => ExternalContentTransformer::DS_DUPLICATE, ExternalContentTransformer::DS_SKIP => ExternalContentTransformer::DS_SKIP);
             $fields->addFieldToTab('Root.Import', new OptionsetField("DuplicateMethod", _t('ExternalContent.DUPLICATES', 'Select how duplicate items should be handled'), $duplicateOptions, $duplicateOptions[ExternalContentTransformer::DS_SKIP]));
             if (class_exists('QueuedJobDescriptor')) {
                 $repeats = array(0 => 'None', 300 => '5 minutes', 900 => '15 minutes', 1800 => '30 minutes', 3600 => '1 hour', 33200 => '12 hours', 86400 => '1 day', 604800 => '1 week');
                 $fields->addFieldToTab('Root.Import', new DropdownField('Repeat', 'Repeat import each ', $repeats));
             }
             $migrateButton = FormAction::create('migrate', _t('ExternalContent.IMPORT', 'Start Importing'))->setAttribute('data-icon', 'arrow-circle-double')->setUseButtonTag(true);
             $fields->addFieldToTab('Root.Import', new LiteralField('MigrateActions', "<div class='Actions'>{$migrateButton->forTemplate()}</div>"));
         }
         $fields->push($hf = new HiddenField("ID"));
         $hf->setValue($id);
         $fields->push($hf = new HiddenField("Version"));
         $hf->setValue(1);
         $actions = new FieldList();
         $actions = CompositeField::create()->setTag('fieldset')->addExtraClass('ss-ui-buttonset');
         $actions = new FieldList($actions);
         // Only show save button if not 'assets' folder
         if ($record->canEdit()) {
             $actions->push(FormAction::create('save', _t('ExternalContent.SAVE', 'Save'))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true));
         }
         if ($isSource && $record->canDelete()) {
             $actions->push(FormAction::create('delete', _t('ExternalContent.DELETE', 'Delete'))->addExtraClass('delete ss-ui-action-destructive')->setAttribute('data-icon', 'decline')->setUseButtonTag(true));
         }
         $form = new Form($this, "EditForm", $fields, $actions);
         if ($record->ID) {
             $form->loadDataFrom($record);
         } else {
             $form->loadDataFrom(array("ID" => "root", "URL" => Director::absoluteBaseURL() . self::$url_segment));
         }
         if (!$record->canEdit()) {
             $form->makeReadonly();
         }
     } else {
         // Create a dummy form
         $fields = new FieldList();
         $form = new Form($this, "EditForm", $fields, new FieldList());
     }
     $form->addExtraClass('cms-edit-form center ss-tabset ' . $this->BaseCSSClasses());
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     $form->setAttribute('data-pjax-fragment', 'CurrentForm');
     $this->extend('updateEditForm', $form);
     return $form;
 }
Exemplo n.º 25
0
 /**
  * Returns a placeholder form, used by {@link getEditForm()} if no record is selected.
  * Our javascript logic always requires a form to be present in the CMS interface.
  * 
  * @return Form
  */
 function EmptyForm()
 {
     $form = new Form($this, "EditForm", new FieldList(), new FieldList());
     $form->unsetValidator();
     $form->addExtraClass('cms-edit-form');
     $form->addExtraClass('root-form');
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     $form->setAttribute('data-pjax-fragment', 'CurrentForm');
     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;
	}
 /**
  * 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;
 }
 function ContactForm()
 {
     error_log("Render form");
     $name = _t('ContactPage.NAME', 'Name');
     $email = _t('ContactPage.EMAIL', 'Email');
     $comments = _t('ContactPage.COMMENTS', 'Comments');
     $send = _t('ContactPage.SEND', 'Send');
     // Create fields
     $tf = new TextField('Name', $name);
     $tf->addExtraClass('span11');
     $ef = new EmailField('Email', $email);
     $ef->addExtraClass('span11');
     $taf = new TextareaField('Comments', $comments);
     $taf->addExtraClass('span11');
     $fields = new FieldList($tf, $ef, $taf);
     // Create action
     $fa = new FormAction('SendContactForm', $send);
     // for bootstrap
     $fa->useButtonTag = true;
     $fa->addExtraClass('btn btn-primary');
     $actions = new FieldList($fa);
     // Create action
     $validator = new RequiredFields('Name', 'Email', 'Comments');
     $form = new Form($this, 'ContactForm', $fields, $actions, $validator);
     $form->setTemplate('VerticalForm');
     $form->addExtraClass('well');
     return $form;
 }
 public function ListViewForm()
 {
     $params = $this->request->requestVar('q');
     if (($module = $this->request->requestVar('Module')) || !empty($params)) {
         $gridField = $this->getModulesGridField($params, $module);
     } else {
         $gridField = $this->getModuleTypesGridField();
     }
     $listview = new Form($this, 'ListViewForm', new FieldList($gridField), new FieldList());
     //$listview->addExtraClass('cms-edit-form');
     $listview->setTemplate($this->getTemplatesWithSuffix('_ListViewForm'));
     // TODO Can't merge $FormAttributes in template at the moment
     $listview->addExtraClass($this->BaseCSSClasses());
     $listview->setAttribute('data-pjax-fragment', 'ListViewForm');
     $this->extend('updateListView', $listview);
     $listview->disableSecurityToken();
     return $listview;
 }
 public function CountriesForm()
 {
     $shopConfig = ShopConfig::get()->First();
     $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Shipping', new HiddenField('ShopConfigSection', null, 'Countries'), new GridField('ShippingCountries', 'Shipping Countries', $shopConfig->ShippingCountries(), GridFieldConfig_RecordEditor::create()->removeComponentsByType('GridFieldFilterHeader')->removeComponentsByType('GridFieldAddExistingAutocompleter'))), new Tab('Billing', new GridField('BillingCountries', 'Billing Countries', $shopConfig->BillingCountries(), GridFieldConfig_RecordEditor::create()->removeComponentsByType('GridFieldFilterHeader')->removeComponentsByType('GridFieldAddExistingAutocompleter')))));
     $actions = new FieldList();
     $form = new Form($this, 'EditForm', $fields, $actions);
     $form->setTemplate('ShopAdminSettings_EditForm');
     $form->setAttribute('data-pjax-fragment', 'CurrentForm');
     $form->addExtraClass('cms-content cms-edit-form center ss-tabset');
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
     }
     $form->setFormAction(Controller::join_links($this->Link($this->sanitiseClassName($this->modelClass)), 'Countries/CountriesForm'));
     $form->loadDataFrom($shopConfig);
     return $form;
 }