function testReadonlyField() { $dropdownField = new DropdownField('FeelingOk', 'Are you feeling ok?', array(0 => 'No', 1 => 'Yes'), '', null, '(Select one)'); $dropdownField->setValue(1); $readonlyDropdownField = $dropdownField->performReadonlyTransformation(); preg_match('/Yes/', $dropdownField->Field(), $matches); $this->assertEquals($matches[0], 'Yes'); }
function getCMSFields() { $fields = new FieldList(); $fields->add(new TextField('Name', 'Name')); $fields->add(new HtmlEditorField('Description', 'Description')); $fields->add(new DropdownField('Status', 'Status', $this->dbObject('Status')->enumValues())); $fields->add($ddl_program = new CheckboxsetField('Program', 'Program', InteropProgramType::get()->filter('HasCapabilities', true)->sort('Order')->map("ID", "ShortName"))); $fields->add($ddl_version = new CheckboxsetField('Version', 'Version', InteropProgramVersion::get()->map("ID", "Name"))); $fields->add($ddl_type = new DropdownField('TypeID', 'Type', Dataobject::get("InteropCapabilityType")->map("ID", "Name", "Please Select"))); if ($this->ID > 0) { $ddl_program->setValue('ID', $this->Program()); $ddl_version->setValue('ID', $this->Version()); $ddl_type->setValue($this->TypeID); } return $fields; }
public function __construct(ISingleValueTemplateQuestion $question, $value = null) { $children = new FieldList(); $this->question = $question; $current_user = Member::currentUser(); $current_affiliations = $current_user->getCurrentAffiliations(); if (!$current_affiliations) { $children->add($txt = new TextField($question->name(), $question->label())); $txt->addExtraClass('input-organization-name'); } else { if (intval($current_affiliations->count()) > 1) { $source = array(); foreach ($current_affiliations as $a) { $org = $a->Organization(); $source[$org->ID] = $org->Name; } $source['0'] = "-- New One --"; $children->add($ddl = new DropdownField($question->name() . 'ID', $question->label(), $source)); $ddl->setEmptyString('-- Select Your Organization --'); $ddl->addExtraClass('select-organization-name'); if (!is_null($value)) { $org = Org::get()->filter('Name', $value)->first(); if ($org) { $ddl->setValue($org->ID); } } $children->add($txt = new TextField($question->name(), '')); $txt->addExtraClass('input-organization-name'); } else { $children->add($txt = new TextField($question->name(), $question->label(), $current_user->getOrgName())); $txt->addExtraClass('input-organization-name'); } } parent::__construct($children); $control_css_class = strtolower($this->question->name() . '-composite'); $this->addExtraClass($control_css_class); Requirements::javascript('survey_builder/js/survey.organization.field.js'); Requirements::customScript("\n jQuery(document).ready(function(\$) {\n \$('.'+'{$control_css_class}').survey_organization_field();\n });"); }
public function __construct($name, $title, $value = null) { $this->name = $name; $this->title = $title; $children = new FieldList(); $source = Company::get()->sort('Name')->map('ID', 'Name')->toArray(); $source['0'] = "-- New Company --"; $children->add($ddl = new DropdownField($name . '_id', $title, $source)); $ddl->setEmptyString('-- Select Your Company --'); $ddl->addExtraClass('select-company-name'); if (!is_null($value)) { $c = Company::get()->filter('Name', $value)->first(); if ($c) { $ddl->setValue($c->ID); } } $children->add($txt = new TextField($name, '')); $txt->addExtraClass('input-company-name'); parent::__construct($children); $control_css_class = strtolower('company-composite'); $this->addExtraClass($control_css_class); Requirements::javascript('openstack/code/utils/CustomHTMLFields/js/company.field.js'); Requirements::customScript("\n jQuery(document).ready(function(\$) {\n \$('.'+'{$control_css_class}').company_field();\n });"); }
function __construct($controller, $name, $speaker = null, $member = null, $email = null) { // Get the city for the current member if ($member) { $country = $member->Country; } else { $country = ''; } // Fields $FirstNameField = new TextField('FirstName', "First Name"); $LastNameField = new TextField('LastName', "Last Name"); $TitleField = new TextField('Title', "Title"); $BioField = new TinyMCEEditorField('Bio', "Bio"); $BioField->addExtraClass('bio'); // Country Field $CountryCodes = CountryCodes::$iso_3166_countryCodes; $CountryField = new DropdownField('Country', 'Country of Residence', $CountryCodes); $CountryField->setEmptyString('-- Select One --'); $CountryField->setValue($country); // ID Fields $SpeakerIDField = new HiddenField('SpeakerID', 'SpeakerID', ""); $MemberIDField = new HiddenField('MemberID', 'MemberID'); // Replace Fields $ReplaceBioField = new HiddenField('ReplaceBio', 'ReplaceBio', 0); $ReplaceNameField = new HiddenField('ReplaceName', 'ReplaceName', 0); $ReplaceSurnameField = new HiddenField('ReplaceSurname', 'ReplaceSurname', 0); // IRC and Twitter $IRCHandleField = new TextField('IRCHandle', 'IRC Handle <em>(Optional)</em>'); $TwiiterNameField = new TextField('TwitterName', 'Twitter Name <em>(Optional)</em>'); // Upload Speaker Photo $PhotoField = new CustomUploadField('Photo', 'Upload a speaker photo'); $PhotoField->setCanAttachExisting(false); $PhotoField->setAllowedMaxFileNumber(1); $PhotoField->setAllowedFileCategories('image'); $PhotoField->setTemplateFileButtons('CustomUploadField_FrontEndFIleButtons'); $PhotoField->setFolderName('profile-images'); $sizeMB = 2; // 1 MB $size = $sizeMB * 1024 * 1024; // 1 MB in bytes $PhotoField->getValidator()->setAllowedMaxFileSize($size); $PhotoField->setCanPreviewFolder(false); // Don't show target filesystem folder on upload field // Opt In Field $OptInField = new CheckboxField('AvailableForBureau', "I'd like to be in the speaker bureau."); $WillingVideoField = new CheckboxField('WillingToPresentVideo', "Willing to present via video conference."); // Funded Travel $FundedTravelField = new CheckboxField('FundedTravel', "My Company would be willing to fund my travel to events."); // Willing to travel $WillingToTravel = new OptionSetField('WillingToTravel', 'I am willing to travel to events:', array(1 => 'Yes', 0 => 'No')); // Countries to travel $CountriesToTravelField = new MultiDropdownField('CountriesToTravel', 'Countries willing to travel to:', $CountryCodes); $CountriesToTravelField->addExtraClass('travel-field'); // Spoken Languages $LanguageField1 = new TextField('Language[1]', '#1'); $LanguageField2 = new TextField('Language[2]', '#2'); $LanguageField3 = new TextField('Language[3]', '#3'); $LanguageField4 = new TextField('Language[4]', '#4'); $LanguageField5 = new TextField('Language[5]', '#5'); // Area of Expertise $ExpertiseField1 = new TextField('Expertise[1]', '#1'); $ExpertiseField2 = new TextField('Expertise[2]', '#2'); $ExpertiseField3 = new TextField('Expertise[3]', '#3'); $ExpertiseField4 = new TextField('Expertise[4]', '#4'); $ExpertiseField5 = new TextField('Expertise[5]', '#5'); // Links To Presentations $PresentationLinkField1 = new TextField('PresentationLink[1]', '#1'); $PresentationTitleField1 = new TextField('PresentationTitle[1]', ''); $PresentationLinkField2 = new TextField('PresentationLink[2]', '#2'); $PresentationTitleField2 = new TextField('PresentationTitle[2]', ''); $PresentationLinkField3 = new TextField('PresentationLink[3]', '#3'); $PresentationTitleField3 = new TextField('PresentationTitle[3]', ''); $PresentationLinkField4 = new TextField('PresentationLink[4]', '#4'); $PresentationTitleField4 = new TextField('PresentationTitle[4]', ''); $PresentationLinkField5 = new TextField('PresentationLink[5]', '#5'); $PresentationTitleField5 = new TextField('PresentationTitle[5]', ''); $NotesField = new TinyMCEEditorField('Notes', "Notes"); $NotesField->addExtraClass('notes'); // Load Existing Data if present if ($speaker) { $this->record = $speaker; $FirstNameField->setValue($speaker->FirstName); $LastNameField->setValue($speaker->LastName); $BioField->setValue($speaker->Bio); $SpeakerIDField->setValue($speaker->ID); $MemberIDField->setValue($speaker->MemberID); $TitleField->setValue($speaker->Title); $IRCHandleField->setValue($speaker->IRCHandle); $TwiiterNameField->setValue($speaker->TwitterName); $PhotoField->setValue(null, $speaker); $OptInField->setValue($speaker->AvailableForBureau); $WillingVideoField->setValue($speaker->WillingToPresentVideo); $FundedTravelField->setValue($speaker->FundedTravel); $WillingToTravel->setValue($speaker->WillingToTravel); $NotesField->setValue($speaker->Notes); foreach ($speaker->AreasOfExpertise() as $key => $expertise) { if ($key > 4) { break; } ${'ExpertiseField' . ($key + 1)}->setValue($expertise->Expertise); } foreach ($speaker->Languages() as $key => $language) { if ($key > 4) { break; } ${'LanguageField' . ($key + 1)}->setValue($language->Language); } $country_array = array(); foreach ($speaker->TravelPreferences() as $pref_country) { $country_array[] = $pref_country->Country; } $CountriesToTravelField->setValue(implode(',', $country_array)); foreach ($speaker->OtherPresentationLinks() as $key => $presentation) { ${'PresentationLinkField' . ($key + 1)}->setValue($presentation->LinkUrl); ${'PresentationTitleField' . ($key + 1)}->setValue($presentation->Title); } } elseif ($member) { $FirstNameField->setValue($member->FirstName); $LastNameField->setValue($member->LastName); $BioField->setValue($member->Bio); $MemberIDField->setValue($member->ID); $IRCHandleField->setValue($member->IRCHandle); $TwiiterNameField->setValue($member->TwitterName); } $fields = new FieldList($FirstNameField, $LastNameField, $TitleField, $CountryField, $BioField, $SpeakerIDField, $MemberIDField, $ReplaceBioField, $ReplaceNameField, $ReplaceSurnameField, $IRCHandleField, $TwiiterNameField, $PhotoField, $OptInField, $WillingVideoField, $FundedTravelField, $WillingToTravel, $CountriesToTravelField, $LanguageField1, $LanguageField2, $LanguageField3, $LanguageField4, $LanguageField5, $ExpertiseField1, $ExpertiseField2, $ExpertiseField3, $ExpertiseField4, $ExpertiseField5, $PresentationLinkField1, $PresentationTitleField1, $PresentationLinkField2, $PresentationTitleField2, $PresentationLinkField3, $PresentationTitleField3, $PresentationLinkField4, $PresentationTitleField4, $PresentationLinkField5, $PresentationTitleField5, $NotesField); $save_action = new FormAction('addAction', 'Save Speaker Details'); $save_action->addExtraClass('btn btn-primary'); $actions = new FieldList($save_action); $validator = new RequiredFields('FirstName', 'LastName', 'Title'); parent::__construct($controller, $name, $fields, $actions, $validator); }
public function ArchiveUnitDropdown() { $months = array(); $months['1'] = _t('filterablearchive.JANUARY', 'Januari'); $months['2'] = _t('filterablearchive.FEBRUARY', 'Februari'); $months['3'] = _t('filterablearchive.MARCH', 'Maart'); $months['4'] = _t('filterablearchive.APRIL', 'April'); $months['5'] = _t('filterablearchive.MAY', 'Mei'); $months['6'] = _t('filterablearchive.JUNE', 'Juni'); $months['7'] = _t('filterablearchive.JULY', 'Juli'); $months['8'] = _t('filterablearchive.AUGUST', 'Augustus'); $months['9'] = _t('filterablearchive.SEPTEMBER', 'September'); $months['10'] = _t('filterablearchive.OCTOBER', 'Oktober'); $months['11'] = _t('filterablearchive.NOVEMBER', 'November'); $months['12'] = _t('filterablearchive.DECEMBER', 'December'); // build array with available archive 'units' $items = $this->owner->getItems(); //$dateField = $this->owner->getFilterableArchiveConfigValue('managed_object_date_field'); $dateField = Config::inst()->get($this->owner->className, 'managed_object_date_field'); $itemArr = array(); foreach ($items as $item) { if (!$item->{$dateField}) { continue; } $dateObj = DBField::create_field('Date', strtotime($item->{$dateField})); // add month if not yet in array; if ($this->owner->ArchiveUnit == 'day') { $arrkey = $dateObj->Format('Y/m/d/'); $arrval = $dateObj->Format('d ') . $months[$dateObj->Format('n')] . $dateObj->Format(' Y'); } elseif ($this->owner->ArchiveUnit == 'month') { $arrkey = $dateObj->Format('Y/m/'); $arrval = $months[$dateObj->Format('n')] . $dateObj->Format(' Y'); } else { $arrkey = $dateObj->Format('Y/'); $arrval = $dateObj->Format('Y'); } if (!array_key_exists($arrkey, $itemArr)) { $itemArr[$arrkey] = $arrval; } } $DrDown = new DropdownField('archiveunits', '', $itemArr); $DrDown->setEmptyString(_t('filterablearchive.FILTER', 'Filter items')); $DrDown->addExtraClass("dropdown form-control"); // specific to the 'archive' action defined by FilterableArchiveHolder_ControllerExtension (if available) $ctrl = Controller::curr(); $activeUnit = ""; if ($ctrl::has_extension("FilterableArchiveHolder_ControllerExtension")) { if ($cYear = $ctrl->getArchiveYear()) { $activeUnit .= "{$cYear}/"; } if ($cMonth = $ctrl->getArchiveMonth()) { $activeUnit .= str_pad("{$cMonth}/", 3, "0", STR_PAD_LEFT); } if ($cDay = $ctrl->getArchiveDay()) { $activeUnit .= str_pad("{$cDay}/", 3, "0", STR_PAD_LEFT); } } $DrDown->setValue($activeUnit); // again, tie this to the 'archive' action; $DrDown->setAttribute('onchange', "location = '{$this->owner->AbsoluteLink()}date/'+this.value;"); return $DrDown; }
function __construct($controller, $name, $speaker = null, $member = null, $email = null) { // Get the city for the current member if ($member) { $country = $member->Country; } else { $country = ''; } // Fields $FirstNameField = new TextField('FirstName', "Speaker's First Name"); $LastNameField = new TextField('LastName', "Speaker's Last Name"); $TitleField = new TextField('Title', "Speaker's Title"); $BioField = new TextAreaField('Bio', "Speaker's Bio"); // ID Fields $SpeakerIDField = new HiddenField('SpeakerID', 'SpeakerID', ""); $MemberIDField = new HiddenField('MemberID', 'MemberID'); // Replace Fields $ReplaceBioField = new HiddenField('ReplaceBio', 'ReplaceBio', 0); $ReplaceNameField = new HiddenField('ReplaceName', 'ReplaceName', 0); $ReplaceSurnameField = new HiddenField('ReplaceSurname', 'ReplaceSurname', 0); // IRC and Twitter $IRCHandleField = new TextField('IRCHandle', 'IRC Handle <em>(Optional)</em>'); $TwiiterNameField = new TextField('TwitterName', 'Twitter Name <em>(Optional)</em>'); // Upload Speaker Photo $PhotoField = new CustomUploadField('Photo', 'Upload a speaker photo'); $PhotoField->setCanAttachExisting(false); $PhotoField->setAllowedMaxFileNumber(1); $PhotoField->setAllowedFileCategories('image'); $PhotoField->setTemplateFileButtons('CustomUploadField_FrontEndFIleButtons'); $PhotoField->setFolderName('profile-images'); $sizeMB = 2; // 1 MB $size = $sizeMB * 1024 * 1024; // 1 MB in bytes $PhotoField->getValidator()->setAllowedMaxFileSize($size); $PhotoField->setCanPreviewFolder(false); // Don't show target filesystem folder on upload field // Opt In Field $OptInField = new CheckboxField('AvailableForBureau', "I'd like to be in the speaker bureau."); $Divider = new LiteralField('hr', '<hr/>'); // Funded Travel $FundedTravelField = new CheckboxField('FundedTravel', "My Company would be willing to fund my travel to events."); // Country Field $CountryCodes = CountryCodes::$iso_3166_countryCodes; $CountryField = new DropdownField('Country', 'Country', $CountryCodes); $CountryField->setEmptyString('-- Select One --'); $CountryField->setValue($country); $ExpertiseField = new TextareaField('Expertise', 'Topics of interest (one per line)'); // Load Existing Data if present if ($speaker) { $this->record = $speaker; $FirstNameField->setValue($speaker->FirstName); $LastNameField->setValue($speaker->LastName); $BioField->setValue($speaker->Bio); $SpeakerIDField->setValue($speaker->ID); $MemberIDField->setValue($speaker->MemberID); $TitleField->setValue($speaker->Title); $IRCHandleField->setValue($speaker->IRCHandle); $TwiiterNameField->setValue($speaker->TwitterName); $OptInField->setValue($speaker->AvailableForBureau); $FundedTravelField->setValue($speaker->FundedTravel); $ExpertiseField->setValue($speaker->Expertise); $PhotoField->setValue(null, $speaker); } elseif ($member) { $FirstNameField->setValue($member->FirstName); $LastNameField->setValue($member->LastName); $BioField->setValue($member->Bio); $MemberIDField->setValue($member->ID); $IRCHandleField->setValue($member->IRCHandle); $TwiiterNameField->setValue($member->TwitterName); } $fields = new FieldList($FirstNameField, $LastNameField, $TitleField, $BioField, $SpeakerIDField, $MemberIDField, $ReplaceBioField, $ReplaceNameField, $ReplaceSurnameField, $IRCHandleField, $TwiiterNameField, $PhotoField, $Divider, $OptInField, $FundedTravelField, $CountryField, $ExpertiseField); $actions = new FieldList(new FormAction('addAction', 'Save Speaker Details')); $validator = new RequiredFields('FirstName', 'LastName', 'Title'); parent::__construct($controller, $name, $fields, $actions, $validator); }
function setValue($val) { if ($val) { if (!$this->multiple && is_array($val)) { throw new InvalidArgumentException('No array values allowed with multiple=false'); } if ($this->multiple) { $parts = is_array($val) ? $val : preg_split("/ *, */", trim($val)); if (ArrayLib::is_associative($parts)) { throw new InvalidArgumentException('No associative arrays allowed multiple=true'); } if ($diff = array_diff($parts, array_keys($this->source))) { throw new InvalidArgumentException(sprintf('Invalid keys "%s" in value array for multiple=true', Convert::raw2xml(implode(',', $diff)))); } parent::setValue($parts); } else { if (!in_array($val, array_keys($this->source))) { throw new InvalidArgumentException(sprintf('Invalid value "%s" for multiple=true', Convert::raw2xml($val))); } parent::setValue($val); } } else { parent::setValue($val); } }
public function MonthJumpForm() { $this->parseURL($this->getRequest()); $dummy = sfDate::getInstance($this->startDate); $range = range($dummy->subtractYear(3)->format('Y'), $dummy->addYear(6)->format('Y')); $year_map = array_combine($range, $range); $f = new Form($this, "MonthJumpForm", new FieldList($m = new DropdownField('Month', '', CalendarUtil::get_months_map('%B')), $y = new DropdownField('Year', '', $year_map)), new FieldList(new FormAction('doMonthJump', _t('Calendar.JUMP', 'Go')))); if ($this->startDate) { $m->setValue($this->startDate->format('m')); $y->setValue($this->startDate->format('Y')); } else { $m->setValue(date('m')); $y->setValue(date('Y')); } return $f; }
/** * Returns the folder selection dropdown to the template * * @param int $id The ID of the folder that is selected * @return DropdownField */ public function FolderDropdown($id = null) { if (!$id) { $id = $this->CurrentUploadFolder()->ID; } if (class_exists("SimpleTreeDropdownField")) { $d = new SimpleTreeDropdownField("UploadFolderID_{$this->id()}", '', "Folder", $id, "Filename"); } else { $folders = DataObject::get("Folder"); $d = new DropdownField("UploadFolderID_{$this->id()}", '', $folders->toDropDownMap("ID", "Title"), $id); } $group = new FieldGroup($d, new LiteralField("slash{$this->id()}", " / "), new TextField("NewFolder_{$this->id()}", ""), $a = new FormAction("ok_{$this->id()}", _t('Uploadify.CHANGEFOLDERACTION', 'Change'))); $a->useButtonTag = true; $a->addExtraClass("{'url' : '" . $this->Link('newfolder') . "' }"); $d->setValue($id); return $group; }
/** * {@inheritdoc} */ public function setValue($value, $source = null) { if ($source instanceof DataObject) { $name = $this->getName(); if ($source->hasMethod($name)) { $value = $source->{$name}()->getIDList(); } } elseif ($value instanceof SS_List) { $value = $value->column('ID'); } return parent::setValue(array_filter($value)); }
/** * Load a value into this CheckboxSetField */ public function setValue($val, $obj = null) { // If we're not passed a value directly, // we can look for it in a relation method on the object passed as a second arg if (!$val && $obj && $obj instanceof DataObject && $obj->hasMethod($this->name)) { $funcName = $this->name; $val = array_values($obj->{$funcName}()->getIDList()); } if ($val) { if (!$this->multiple && is_array($val)) { throw new InvalidArgumentException('No array values allowed with multiple=false'); } if ($this->multiple) { $parts = is_array($val) ? $val : preg_split("/ *, */", trim($val)); if (ArrayLib::is_associative($parts)) { throw new InvalidArgumentException('No associative arrays allowed multiple=true'); } // Doesn't check against unknown values in order to allow for less rigid data handling. // They're silently ignored and overwritten the next time the field is saved. parent::setValue($parts); } else { if (!in_array($val, array_keys($this->getSource()))) { throw new InvalidArgumentException(sprintf('Invalid value "%s" for multiple=false', Convert::raw2xml($val))); } parent::setValue($val); } } else { parent::setValue($val); } return $this; }
/** * {@inheritdoc} */ public function setValue($value, $source = null) { if (is_string($value)) { $value = explode(',', $value); } if ($source instanceof DataObject) { $name = $this->getName(); $value = explode(',', $source->{$name}); } if ($source instanceof SS_List) { $value = $source->column('ID'); } if (is_null($value)) { $value = array(); } return parent::setValue(array_filter($value)); }
protected function augmentMailChimpField(FormField $field, string $component, FlexiFormMailChimpClient $client) { switch ($component) { case 'MailChimpSendWelcome': $field->setTitle('Send Welcome Email'); $field->description = 'flag to control whether the Welcome Email is sent. Has no effect if double opt-in is enabled.'; break; case 'MailChimpDoubleOptIn': $field->setTitle('Require Double Opt-In'); $field->description = 'flag to control whether a double opt-in confirmation message is sent, defaults to true. Abusing this may cause your account to be suspended.'; break; case 'MailChimpEmailField': $field->setTitle('Subscription Field'); $field->description = 'Used as the subscriber email. Must be an Email Field or subclass.'; break; case 'MailChimpEmailType': // @TODO ought to let user select preference through a form field [ similar to interest groups? ] $field->setTitle('Email Preference'); $field->description = 'email type preference for subscribers (html or text - defaults to html)'; break; case 'MailChimpApiKey': if ($client->isApiKeyValid()) { $field->description = 'This API Key is Valid.'; } else { if ($client->getApiKey() == '') { $field->description = 'Your MailChimp API Key. Found under Account Extras > Your API Keys'; } else { $field->description = 'This API Key is not Valid.'; } } $field->setTitle('MailChimp API Key'); break; case 'MailChimpListID': if ($lists = $client->getLists(array('limit' => 100, 'sort_field' => 'web'))) { $value = $field->Value(); $source = array('' => 'Please Select a List'); $field = new DropdownField($field->getName()); $field->description = 'Subscribers will be added to this list. Lists are refreshed every 10 minutes.'; if ($lists['total'] > 0) { foreach ($lists['data'] as $list) { $source[$list['id']] = $list['name']; } } $field->setValue($value); $field->setSource($source); } else { $field = $field->performReadonlyTransformation(); if (!$client->isApiKeyValid()) { $field->setValue('Invalid API Key'); } else { $field->setValue('Error loading Lists from your Account'); } } $field->setTitle('MailChimp List ID'); break; } return $field; }
/** * Add fields for shipping address and required fields to the validator. * * @param Array $fields Array of fields * @param OrderFormValidator $validator Checkout form validator */ private function addShippingAddressFields(&$fields, &$validator) { $firstNameField = new TextField('Shipping[FirstName]', _t('CheckoutPage.FIRSTNAME', "First Name")); $firstNameField->addExtraClass('shipping-firstname'); $firstNameField->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_FIRSTNAME', "Please enter a first name.")); $surnameField = new TextField('Shipping[Surname]', _t('CheckoutPage.SURNAME', "Surname")); $surnameField->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_SURNAME', "Please enter a surname.")); $addressField = new TextField('Shipping[Address]', _t('CheckoutPage.ADDRESS1', "Address 1")); $addressField->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_ADDRESS', "Please enter an address.")); $cityField = new TextField('Shipping[City]', _t('CheckoutPage.CITY', "City")); $cityField->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_CITY', "Please enter a city.")); $countryField = new DropdownField('Shipping[Country]', _t('CheckoutPage.COUNTRY', "Country"), Country::shipping_countries()); $countryField->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_COUNTRY', "Please enter a country.")); if (!Member::currentUserID() && Geoip::$default_country_code) { $countryField->setValue(Geoip::$default_country_code); } $regions = Region::shipping_regions(); $regionField = null; if (!empty($regions)) { $regionField = new RegionField('Shipping[Region]', _t('CheckoutPage.REGION', "Region")); $regionField->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_REGION', "Please enter a country.")); } $sameAddressField = new CheckboxField('ShipToBillingAddress', _t('CheckoutPage.SAME_ADDRESS', "to same address?")); $sameAddressField->addExtraClass('shipping-same-address'); $shippingAddressFields = new CompositeField(new HeaderField(_t('CheckoutPage.SHIPPING_ADDRESS', "Shipping Address"), 3), $sameAddressField, $firstNameField, $surnameField, new TextField('Shipping[Company]', _t('CheckoutPage.COMPANY', "Company")), $addressField, new TextField('Shipping[AddressLine2]', _t('CheckoutPage.ADDRESS2', "Address 2")), $cityField, new TextField('Shipping[PostalCode]', _t('CheckoutPage.POSTAL_CODE', "Postal Code")), new TextField('Shipping[State]', _t('CheckoutPage.STATE', "State")), $countryField); if ($regionField) { $shippingAddressFields->push($regionField); } $shippingAddressFields->setID('ShippingAddress'); $fields['ShippingAddress'][] = $shippingAddressFields; $validator->addRequiredField('Shipping[FirstName]'); $validator->addRequiredField('Shipping[Surname]'); $validator->addRequiredField('Shipping[Address]'); $validator->addRequiredField('Shipping[City]'); $validator->addRequiredField('Shipping[Country]'); }
/** * Presets the given dropdown field with the default tax rate * * @param DropdownField $dropdownField Dropdown field to manipulate * @param DataObject $object Tax rate related object * @param string $relationName Tax rate relation name * * @return SilvercartTax * * @author Sebastian Diel <*****@*****.**> * @since 26.10.2012 */ public static function presetDropdownWithDefault($dropdownField, $object, $relationName = 'SilvercartTax') { $relationIDName = $relationName . 'ID'; $dropdownField->setEmptyString(''); $dropdownField->setHasEmptyDefault(false); if ($object->{$relationIDName} == 0) { $defaultTaxRate = self::getDefault(); if ($defaultTaxRate) { $dropdownField->setValue($defaultTaxRate->ID); } } }
public function getHTMLFragments($gridField) { $fields = new ArrayList(); $state = $gridField->State->UserFormsGridField; $selectedField = $state->filter; $selectedValue = $state->value; // show dropdown of all the fields available from the submitted form fields // that have been saved. Takes the titles from the currently live form. $columnField = new DropdownField('FieldNameFilter', ''); $columnField->setSource($this->columns); $columnField->setEmptyString(_t('UserFormsGridFieldFilterHeader.FILTERSUBMISSIONS', 'Filter Submissions..')); $columnField->setHasEmptyDefault(true); $columnField->setValue($selectedField); $valueField = new TextField('FieldValue', '', $selectedValue); $columnField->addExtraClass('ss-gridfield-sort'); $columnField->addExtraClass('no-change-track'); $valueField->addExtraClass('ss-gridfield-sort'); $valueField->addExtraClass('no-change-track'); $valueField->setAttribute('placeholder', _t('UserFormsGridFieldFilterHeader.WHEREVALUEIS', 'where value is..')); $fields->push(new FieldGroup(new CompositeField($columnField, $valueField))); $fields->push(new FieldGroup(new CompositeField($start = new DateField('StartFilter', 'From'), $end = new DateField('EndFilter', 'Till')))); foreach (array($start, $end) as $date) { $date->setConfig('showcalendar', true); $date->setConfig('dateformat', 'y-mm-dd'); $date->setConfig('datavalueformat', 'y-mm-dd'); $date->addExtraClass('no-change-track'); } $end->setValue($state->end); $start->setValue($state->start); $fields->push($actions = new FieldGroup(GridField_FormAction::create($gridField, 'filter', false, 'filter', null)->addExtraClass('ss-gridfield-button-filter')->setAttribute('title', _t('GridField.Filter', "Filter"))->setAttribute('id', 'action_filter_' . $gridField->getModelClass() . '_' . $columnField), GridField_FormAction::create($gridField, 'reset', false, 'reset', null)->addExtraClass('ss-gridfield-button-close')->setAttribute('title', _t('GridField.ResetFilter', "Reset"))->setAttribute('id', 'action_reset_' . $gridField->getModelClass() . '_' . $columnField))); $actions->addExtraClass('filter-buttons'); $actions->addExtraClass('no-change-track'); $forTemplate = new ArrayData(array('Fields' => $fields)); return array('header' => $forTemplate->renderWith('GridFieldFilterHeader_Row')); }