/** * 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; }