public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByname('ParentID'); $fields->removeByname('Latitude'); $fields->removeByname('Longitude'); $fields->removeByname('Zoom'); $fields->removeByname('Sort'); $fields->addFieldsToTab("Root.Map", array(HeaderField::create("MapHeader", _t("GoogleMaps.MapHeader", "Generate your map")), GoogleMapField::create($this, "Find the location"), ReadOnlyField::create("Latitude"), ReadOnlyField::create("Longitude"), ReadOnlyField::create("Zoom"))); return $fields; }
/** * Standard SS method * @return FieldSet */ function getCMSFields() { //backup in case there are no products. if (Product::get()->count() == 0) { return parent::getCMSFields(); } $product = $this->Product(); $productField = new DropdownField('ProductID', _t("ProductVariation.PRODUCT", 'Product'), Product::get()->map('ID', 'Title')->toArray()); $productField->setEmptyString('(Select one)'); $fields = new FieldList(new TabSet('Root', new Tab('Main', $productField, $fullNameLinkField = ReadOnlyField::create('FullNameLink', _t("ProductVariation.FULLNAME", 'Full Name'), "<a href=\"" . $this->Link() . "\">" . $this->FullName . "</a>"), new NumericField('Price', _t("ProductVariation.PRICE", 'Price')), new CheckboxField('AllowPurchase', _t("ProductVariation.ALLOWPURCHASE", 'Allow Purchase ?'))), new Tab('Details', new TextField('InternalItemID', _t("ProductVariation.INTERNALITEMID", 'Internal Item ID')), new TextField('Description', _t("ProductVariation.DESCRIPTION", "Description (optional)"))), new Tab('Image', new Product_ProductImageUploadField('Image')))); $fullNameLinkField->dontEscape = true; if ($this->EcomConfig()->ProductsHaveWeight) { $fields->addFieldToTab('Root.Details', new NumericField('Weight', _t('ProductVariation.WEIGHT', 'Weight'))); } if ($this->EcomConfig()->ProductsHaveModelNames) { $fields->addFieldToTab('Root.Details', new TextField('Model', _t('ProductVariation.MODEL', 'Model'))); } if ($this->EcomConfig()->ProductsHaveQuantifiers) { $fields->addFieldToTab('Root.Details', new TextField('Quantifier', _t('ProductVariation.QUANTIFIER', 'Quantifier (e.g. per kilo, per month, per dozen, each)'))); } $fields->addFieldToTab('Root.Details', new ReadOnlyField('FullSiteTreeSort', _t('Product.FULLSITETREESORT', 'Full sort index'))); if ($product) { $types = $product->VariationAttributes(); if ($this->ID) { $hasBeenSold = $this->HasBeenSold(); $values = $this->AttributeValues(); foreach ($types as $type) { $field = $type->getDropDownField(); if ($field) { $value = $values->find('TypeID', $type->ID); if ($value) { $field->setValue($value->ID); if ($hasBeenSold) { $field = $field->performReadonlyTransformation(); $field->setName("Type{$type->ID}"); } } else { if ($hasBeenSold) { $field = new ReadonlyField("Type{$type->ID}", $type->Name, _t("ProductVariation.ALREADYPURCHASED", 'NOT SET (you can not select a value now because it has already been purchased).')); } else { $field->setEmptyString(''); } } } else { $field = new ReadonlyField("Type{$type->ID}", $type->Name, _t("ProductVariation.NOVALUESTOSELECT", 'No values to select')); } $fields->addFieldToTab('Root.Attributes', $field); } } else { foreach ($types as $type) { $field = $type->getDropDownField(); $fields->addFieldToTab('Root.Attributes', $field); } } } $fields->addFieldToTab('Root.Main', new LiteralField('AddToCartLink', "<p class=\"message good\"><a href=\"" . $this->AddLink() . "\">" . _t("Product.ADD_TO_CART", "add to cart") . "</a></p>")); $this->extend('updateCMSFields', $fields); return $fields; }
/** * @expectedException \RuntimeException * */ public function testReadOnlyFieldGetDataNotWorking() { $ro = new ReadOnlyField(); $ro->getData(); }
function Form() { $array = array(); $array[] = "green"; $array[] = "yellow"; $array[] = "blue"; $array[] = "pink"; $array[] = "orange"; $errorField0 = new TextField($name = "ErrorField0", $title = "Text Field Example 1"); $errorField0->setError("message shown when something is good", "good"); $errorField1 = new TextField($name = "ErrorField1", $title = "Text Field Example 2"); $errorField1->setError("message shown when something is bad", "bad"); $errorField2 = new TextField($name = "ErrorField2", $title = "Text Field Example 3"); $errorField2->setCustomValidationMessage("message shown when something is bad", "bad"); $errorField3 = new TextField($name = "ErrorField3", $title = "Text Field Example 4"); $errorField3->setError("there is an error", "required"); $errorField4 = new TextField($name = "ErrorField4", $title = "Text Field Example 5"); $errorField4->setCustomValidationMessage("custom validation error"); $rightTitle = new TextField($name = "RightTitleField", $title = "Left Title is Default"); $rightTitle->setRightTitle("right title here"); $readonlyField = new ReadOnlyField($name = "ReadOnlyField", $title = "ReadOnlyField"); $readonlyField->setValue("read only value"); $groupedDropdownField = new GroupedDropdownField($name = "dropdown", $title = "Simple Grouped Dropdown", $source = array("primary" => array("1" => "Green", "2" => "Red", "3" => "Blue", "4" => "Orange"), "secondary" => array("11" => "Light Blue", "12" => "Dark Brown", "13" => "Pinkish Red"))); $form = new Form($controller = $this, $name = "TestForm", $fields = new FieldList(new HeaderField($name = "HeaderField1", $title = "Default Header Field"), new LiteralField($name = "LiteralField", "<p>NOTE: All fields up to EmailField are required and should be marked as such</p>"), new TextField($name = "TextField1", $title = "Text Field Example 1"), new TextField($name = "TextField2", $title = "Text Field Example 2"), new TextField($name = "TextField3", $title = "Text Field Example 3"), new TextField($name = "TextField4", $title = ""), new HeaderField($name = "HeaderField2a", $title = "Error Messages", 2), new LiteralField($name = "ErrorExplanations", '<p>Below are some error messages, some of them only show up after you have placed your cursor on the field and not completed it (i.e. a reminder to complete the field)</p>'), $errorField0, $errorField1, $errorField2, $errorField3, $errorField4, new HeaderField($name = "HeaderField2b", $title = "Field with right title", 2), $rightTitle, $textAreaField = new TextareaField($name = "TextareaField", $title = "Textarea Field"), new EmailField("EmailField", "Email address"), new HeaderField($name = "HeaderField2c", $title = "HeaderField Level 2", 2), new DropdownField($name = "DropdownField", $title = "Dropdown Field", array(0 => "-- please select --", 1 => "test AAAA", 2 => "test BBBB")), new OptionsetField($name = "OptionsetField", $title = "Optionset Field", $array), new CheckboxSetField($name = "CheckboxSetField", $title = "Checkbox Set Field", $array), new CurrencyField($name = "CurrencyField", $title = "Bling bling"), new HeaderField($name = "HeaderField3", $title = "Other Fields", 3), new NumericField($name = "NumericField", $title = "Numeric Field "), new DateField($name = "DateField", $title = "Date Field"), new DateField($name = "DateTimeField", $title = "Date and Time Field"), new FileField($name = "FileField", $title = "File Field"), new UploadField($name = "UploadField", $title = "Upload File"), new ConfirmedPasswordField($name = "ConfirmPasswordField", $title = "Password"), new CheckboxField($name = "CheckboxField", $title = "Checkbox Field"), $groupedDropdownField, new HeaderField($name = "HeaderField4", $title = "Read-only Field", 3), $readonlyField), $actions = new FieldList(new FormAction("signup", "Sign up")), $requiredFields = new RequiredFields("TextField1", "TextField2", "TextField3", "ErrorField1", "ErrorField2", "EmailField", "TextField3", "RightTitleField", "CheckboxField", "CheckboxSetField")); $textAreaField->setColumns(7); $form->setMessage("warning message", "warning"); return $form; }