public function __construct($controller, $name) { $this->controller = $controller; $userSubmissionHolder = $this->controller->data(); $editableFormFields = $userSubmissionHolder->Fields()->filter(array('EnableOnSearchForm' => true)); $fields = new FieldList(); foreach ($editableFormFields as $editableFormField) { $field = $this->getFormFieldFromEditableFormField($editableFormField); if ($field) { $fields->push($field); } } $willCreateKeywordsField = $userSubmissionHolder->Fields()->find('UseInKeywordSearch', true); if ($willCreateKeywordsField) { $fields->unshift($field = TextField::create('Keywords', 'Keywords')); } $actions = new FieldList($submitButton = FormAction::create('doSearch', 'Search')->setUseButtonTag($this->config()->submit_use_button_tag)->addExtraClass($this->config()->submit_classes)); $validator = UserSubmissionSearchFormValidator::create(); $validator->fields = $fields; parent::__construct($controller, $name, $fields, $actions, $validator); $this->disableSecurityToken(); // Retain search text and selections for pagination pages // (as pagination doesn't trigger the httpSubmission function) $this->loadDataFrom($controller->getRequest()->requestVars()); // note(Jake): Probably the perfect way to extend the form. Leaving commented until real use case arises. //$this->extend('updateForm'); }
/** * Set if the existing password should be required * * @param bool $show Flag to show or hide this field * @return $this */ public function setRequireExistingPassword($show) { // Don't modify if already added / removed if ((bool) $show === $this->requireExistingPassword) { return $this; } $this->requireExistingPassword = $show; $name = $this->getName(); $currentName = "{$name}[_CurrentPassword]"; if ($show) { $confirmField = PasswordField::create($currentName, _t('Member.CURRENT_PASSWORD', 'Current Password')); $this->children->unshift($confirmField); } else { $this->children->removeByName($currentName, true); } return $this; }
/** * @return FieldList */ public function Actions() { if (!$this->getCanAddInline()) { return new FieldList(); } if ($this->actions) { return $this->actions; } // Setup default actions $this->actions = new FieldList(); $this->actions->unshift($inlineAddButton = FormAction::create('AddInlineRecord', 'Add')->addExtraClass('multirecordfield-addinlinebutton js-multirecordfield-add-inline')->setAttribute('autocomplete', 'off')->setUseButtonTag(true)); $this->actions->unshift($classField = DropdownField::create('ClassName', ' ')->addExtraClass('multirecordfield-classname js-multirecordfield-classname')->setAttribute('autocomplete', 'off')->setEmptyString('(Select section type to create)')); $inlineAddButton->addExtraClass('ss-ui-action-constructive ss-ui-button'); $inlineAddButton->setAttribute('data-icon', 'add'); // NOTE(Jake): add 'updateActions' here if needed later. // Update FormAction fields with button classes // todo(Jake): Find a better location for applying this $this->applyButtonClasses($this->actions); return $this->actions; }
/** * @param Controller $controller * @param String $name * @param GroupedProduct $product */ public function __construct($controller, $name, GroupedProduct $product) { $fields = new FieldList(); // add quantity etc fields // TODO: These should probably be cleaned up and put in composite fields or something foreach ($product->ChildProducts() as $child) { if (!$child->hasExtension('GroupedCartFormChildHooks')) { user_error('Child Products must have GroupedCartFormChildHooks applied.'); } $vars = $child->hasMethod('Variations') ? $child->Variations() : null; if ($vars && $vars->count() > 0) { foreach ($child->getVariationFields() as $f) { $fields->push($f); } } $fields->push($child->getQuantityField()); } $actions = new FieldList(array(FormAction::create('addtocart', _t('GroupedCartForm.ADD', 'Add to Cart')))); // integrate with wishlist module if (class_exists('WishList')) { $actions->unshift(FormAction::create('addtowishlist', _t('GroupedCartForm.ADDTOWISHLIST', 'Add to Wish List'))); } parent::__construct($controller, $name, $fields, $actions); }
/** * Add a new child field to the beginning of the set. * * @param FormField */ public function unshift(FormField $field) { $this->children->unshift($field); }
function updateCMSFields(FieldList $fields) { $fields->removeByName('Published'); $fields->unshift(CheckboxField::create('Published', _t('CMSPublishableDataExtension.PUBLISHED', 'Published'))); return $fields; }
/** * Test pushing a field to the beginning of a set. * * This tests {@link FieldList->unshift()}. */ public function testPushFieldToBeginningOfSet() { $fields = new FieldList(); /* A field named Country is added to the set */ $fields->unshift(new TextField('Country')); /* We only have 1 field in the set */ $this->assertEquals(1, $fields->Count()); /* Another field called Email is added to the set */ $fields->unshift(new EmailField('Email')); /* There are now 2 fields in the set */ $this->assertEquals(2, $fields->Count()); /* The most recently added field is at the beginning of the set */ $this->assertEquals('Email', $fields->First()->getName()); // Test that pushing a composite field without a name onto the set works $fields->unshift(new CompositeField(new TextField('Test1'), new TextField('Test2'))); $this->assertEquals(3, $fields->Count()); }
public function getCMSFields() { $fields = new FieldList($this->getCMSFieldsForVideo()); $fields->unshift(new TextField('Title', 'Title/Label (optional)')); return $fields; }
/** * Adds a UI message to indicate whether you're editing in the default locale or not * * @param FieldList $fields * @return $this */ protected function addLocaleIndicatorMessage(FieldList $fields) { if (Fluent::config()->disable_current_locale_message) { return $this; } // If the field is already present, don't add it a second time if ($fields->fieldByName('CurrentLocaleMessage')) { return $this; } $localeNames = Fluent::locale_names(); $isDefaultLocale = Fluent::default_locale() === Fluent::current_locale(); $messageClass = $isDefaultLocale ? 'good' : 'notice'; $message = $isDefaultLocale ? _t('Fluent.DefaultLocale', 'This is the default locale') : _t('Fluent.DefaultLocaleIs', 'The default locale is') . ' ' . $localeNames[Fluent::default_locale()]; $fields->unshift(LiteralField::create('CurrentLocaleMessage', sprintf('<p class="message %s">' . _t('Fluent.EditingIn', 'Please note: You are editing in') . ' %s. %s.</p>', $messageClass, $localeNames[Fluent::current_locale()], $message))); return $this; }