/** * @return FieldList */ public function getCMSFields() { if (!$this->exists()) { // The new module state Requirements::css(MODULATOR_PATH . '/css/PageModule.css'); Requirements::javascript(MODULATOR_PATH . '/javascript/PageModule.js'); $allowedModules = array(); // Determine the type of the parent page $currentPageID = Session::get('CMSMain.currentPage'); if ($currentPageID) { $currentPage = SiteTree::get_by_id('SiteTree', $currentPageID); if ($currentPage) { $currentPageClass = $currentPage->ClassName; // Get the list of allowed modules for this page type if (class_exists($currentPageClass) && method_exists($currentPageClass, 'getAllowedModules')) { $allowedModules = $currentPageClass::getAllowedModules(); } } } $classList = array(); foreach ($allowedModules as $class) { $instance = new $class(); $classList[$class] = '<img src="' . $instance::$icon . '"><strong>' . $class::$label . '</strong><p>' . $class::$description . '</p>'; } $fields = new FieldList(); if (!count($allowedModules)) { $typeField = new LiteralField('Type', '<span class="message required">There are no module types defined, please create some.</span>'); $fields->push($typeField); } else { $labelField = new TextField('Title', 'Label'); $labelField->setDescription('A reference name for this block, not displayed on the website'); $fields->push($labelField); $typeField = new OptionSetField('NewClassName', 'Type', $classList); $typeField->setDescription('The type of module determines what content and functionality it will provide'); $fields->push($typeField); } $this->extend('updateCMSFields', $fields); } else { // Existing module state $fields = parent::getCMSFields(); // Don't expose Order to the CMS $fields->removeFieldFromTab('Root.Main', 'Order'); $fields->removeFieldFromTab('Root.Main', 'PageID'); // Helps us keep track of preview focus $fields->addFieldToTab('Root.Main', new HiddenField('ModulatorID', 'ModulatorID', $this->ID)); } return $fields; }
/** * Method that turns this object into a field type, to be loaded into a form * * @return FormField */ public function Field() { if ($this->Title && $this->DisplayAs) { $name = "customise_{$this->ID}_" . Convert::raw2url($this->Title); $title = $this->Required ? $this->Title . ' *' : $this->Title; $options = $this->Options()->map('Title', 'ItemSummary'); $defaults = $this->DefaultOptions(); $default = $defaults->exists() ? $defaults->first()->Title : null; switch ($this->DisplayAs) { case 'Dropdown': $field = DropdownField::create($name, $title, $options, $default)->setEmptyString(_t('Commerce.PleaseSelect', 'Please Select'))->setAttribute("class", "dropdown btn"); break; case 'Radio': $field = OptionSetField::create($name, $title, $options, $default); break; case 'Checkboxes': $field = CheckboxSetField::create($name, $title, $options, $defaults->column('ID')); break; case 'TextEntry': $field = TextField::create($name, $title); if ($this->MaxLength) { $field->setMaxLength($this->MaxLength); } break; } $this->extend('updateField', $field); return $field; } else { return false; } }
public function getCMSFields($params = null) { //fields that shouldn't be changed once coupon is used $fields = new FieldList(array($tabset = new TabSet("Root", $maintab = new Tab("Main", TextField::create("Title"), CheckboxField::create("Active", "Active")->setDescription("Enable/disable all use of this discount."), HeaderField::create("ActionTitle", "Action", 3), $typefield = SelectionGroup::create("Type", array(new SelectionGroup_Item("Percent", $percentgroup = FieldGroup::create($percentfield = NumericField::create("Percent", "Percentage", "0.00")->setDescription("e.g. 0.05 = 5%, 0.5 = 50%, and 5 = 500%"), $maxamountfield = CurrencyField::create("MaxAmount", _t("MaxAmount", "Maximum Amount"))->setDescription("The total allowable discount. 0 means unlimited.")), "Discount by percentage"), new SelectionGroup_Item("Amount", $amountfield = CurrencyField::create("Amount", "Amount", "\$0.00"), "Discount by fixed amount")))->setTitle("Type"), OptionSetField::create("For", "Applies to", array("Order" => "Entire Order", "Cart" => "Cart Subtotal", "Shipping" => "Shipping Subtotal", "Items" => "Each Individual Item")), new Tab("Main", HeaderField::create("ConstraintsTitle", "Constraints", 3), LabelField::create("ConstraintsDescription", "Configure the requirements an order must meet for this discount to be valid:")), new TabSet("Constraints"))))); if (!$this->isInDB()) { $fields->addFieldToTab("Root.Main", LiteralField::create("SaveNote", "<p class=\"message good\">More constraints will show up after you save for the first time.</p>"), "Constraints"); } $this->extend("updateCMSFields", $fields, $params); if ($count = $this->getUseCount()) { $fields->addFieldsToTab("Root.Usage", array(HeaderField::create("UseCount", sprintf("This discount has been used {$count} time%s.", $count > 1 ? "s" : "")), HeaderField::create("TotalSavings", sprintf("A total of %s has been saved by customers using this discount.", $this->SavingsTotal), "3"), GridField::create("Orders", "Orders", $this->getAppliedOrders(), GridFieldConfig_RecordViewer::create()->removeComponentsByType("GridFieldViewButton")))); } if ($params && isset($params['forcetype'])) { $valuefield = $params['forcetype'] == "Percent" ? $percentfield : $amountfield; $fields->insertAfter($valuefield, "Type"); $fields->removeByName("Type"); } elseif ($this->Type && (double) $this->{$this->Type}) { $valuefield = $this->Type == "Percent" ? $percentfield : $amountfield; $fields->removeByName("Type"); $fields->insertAfter($valuefield, "ActionTitle"); $fields->replaceField($this->Type, $valuefield->performReadonlyTransformation()); if ($this->Type == "Percent") { $fields->insertAfter($maxamountfield, "Percent"); } } return $fields; }
public function getCMSFields() { if ($this->ID == 0) { $categorydropdown = TextField::create('CategoryDisclaimer')->setTitle('Category')->setDisabled(true)->setValue('You can assign a category once you have saved the record for the first time.'); } else { $categories = ListCategory::get()->filter("ListPageID", "{$this->ListPageID}")->sort("Category ASC"); $map = $categories ? $categories->map('ID', 'Category', 'Please Select') : array(); if ($map) { $categorydropdown = new DropdownField('ListCategoryID', 'Category', $map); $categorydropdown->setEmptyString("-- Please Select --"); } else { $categorydropdown = new DropdownField('ListCategoryID', 'Category', $map); $categorydropdown->setEmptyString("There are no categories created yet"); } } $ImageField = UploadField::create('Photo')->setDescription('(Allowed filetypes: jpg, jpeg, png, gif)'); $ImageField->folderName = 'ListPage'; $ImageField->getValidator()->allowedExtensions = array('jpg', 'jpeg', 'gif', 'png'); $DocumentField = UploadField::create('Resource')->setTitle('Resource/Document')->setDescription('(Allowed filetypes: pdf, doc, docx, txt, ppt, or pptx)'); $DocumentField->folderName = "ListPage"; $DocumentField->getValidator()->allowedExtensions = array('pdf', 'doc', 'docx', 'txt', 'ppt', 'pptx'); $LinkField = TextField::create('Link')->setTitle('Link URL'); $fields = FieldList::create(TabSet::create('Root')); $fields->addFieldsToTab('Root.Main', array($categorydropdown, TextField::create('Title'), OptionSetField::create('LinkType')->setTitle('')->setSource($this->dbObject('LinkType')->enumValues()), TextField::create('Link')->setTitle('Link URL')->displayIf('LinkType')->isEqualTo('Link')->andIf('LinkType')->isNotEqualTo('Resource')->end(), DisplayLogicWrapper::create($DocumentField)->displayIf('LinkType')->isEqualTo('Resource')->andIf('LinkType')->isNotEqualTo('Link')->end(), $ImageField, HTMLEditorField::create('Content'))); return $fields; }
/** * Returns a FieldList of cms form fields * * @return FieldList */ public function getCMSFields() { $fields = parent::getCMSFields(); // Hide these from editing $fields->removeByName('ParentID'); $fields->removeByName('Sort'); //Remove to re-add $fields->removeByName('Type'); $fields->removeByName('LinkLabel'); $content = $fields->dataFieldByName('Content'); $numberToDisplay = $fields->dataFieldByName('NumberToDisplay'); $projectPage = $fields->dataFieldByName('ProjectPageID'); $html = $fields->dataFieldByName('HTML'); $subtitle = $fields->dataFieldByName('SubTitle'); $html->setRows(20); $html->addExtraClass('no-pagebreak'); $link = $fields->dataFieldByName('LinkID'); $image = $fields->dataFieldByName('Image'); $image->setFolderName('Uploads/Small-Images'); $fields->removeByName('Image'); $fields->insertBefore($projectPage, 'Content'); $fields->insertAfter($type = OptionSetField::create("Type", "Type", $this->dbObject('Type')->enumValues()), "Colour"); $type->addExtraClass('inline-short-list'); $fields->insertAfter(ColorPaletteField::create("Colour", "Colour", array('night' => '#333333', 'air' => '#009EE2', 'earth' => ' #79c608', 'passion' => '#b02635', 'people' => '#de347f', 'inspiration' => '#783980')), "Title"); $fields->insertAfter($linkLabel = new TextField("LinkLabel", "Link Label"), "LinkID"); $fields->insertAfter($imageLogin = DisplayLogicWrapper::create($image), 'LinkLabel'); $imageLogin->hideUnless("Type")->isEqualTo("Content"); $html->hideUnless("Type")->isEqualTo("HTML"); $subtitle->hideUnless("Type")->isEqualTo("HTML"); $link->hideUnless("Type")->isEqualTo("Content")->orIf("Type")->isEqualTo("Project"); $linkLabel->hideUnless("LinkID")->isGreaterThan(0)->andIf("Type")->isEqualTo("Content"); $numberToDisplay->hideIf("Type")->isEqualTo("Content")->orIf("Type")->isEqualTo("HTML"); $projectPage->hideUnless("Type")->isEqualTo("Project"); $content->hideUnless("Type")->isEqualTo("Content"); // Archived $fields->removeByName('Archived'); $fields->addFieldToTab('Root.Main', $group = new CompositeField($label = new LabelField("LabelArchive", "Archive this feature?"), new CheckboxField('Archived', ''))); $group->addExtraClass("special field"); $label->addExtraClass("left"); return $fields; }
/** * @param ISurveyStep $current_step * @param ISurveyQuestionTemplate $question * @param ISurveyAnswer $answer * @return FormField */ public function build(ISurveyStep $current_step, ISurveyQuestionTemplate $question, ISurveyAnswer $answer) { $options = array(); foreach ($question->Values()->sort('Order') as $val) { $options[$val->ID] = empty($val->Label) ? $val->Value : $val->Label; } $field = new OptionSetField($question->name(), $question->label(), $options); $default_value = $question->getDefaultValue(); if (!is_null($default_value) && $default_value->ID > 0) { $field->setValue($default_value->ID); } if ($question->isReadOnly()) { $field->setDisabled(true); } if ($question->isMandatory()) { $field->setAttribute('data-rule-required', 'true'); } if (!is_null($answer)) { $field->setValue($answer->value()); } $this->buildDependantRules($current_step, $question, $field); return $field; }
/** * Retrieve the {@link OptionsetField} for stock choice for display in CMS. * * @return String */ function StockChoiceField() { $stockChoiceValue = $this->value == -1 ? 0 : 1; $this->stockChoiceField->setValue($stockChoiceValue); return $this->stockChoiceField->SmallFieldHolder(); }
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); }