/**
  * Used in getCSMFields
  * @return GridField
  **/
 protected function getProductGroupsTable()
 {
     $gridField = GridField::create("AlsoShowProducts", _t("ProductGroup.OTHER_PRODUCTS_SHOWN_IN_THIS_GROUP", "Other products shown in this group ..."), $this->AlsoShowProducts(), GridFieldEditOriginalPageConfigWithDelete::create());
     //make sure edits are done in the right place ...
     return $gridField;
 }
 /**
  * Used in getCSMFields
  * @return GridField
  **/
 protected function getProductGroupsTableField()
 {
     $gridField = new GridField("ProductGroups", _t("Product.THIS_PRODUCT_SHOULD_ALSO_BE_LISTED_UNDER", "This product is also listed under ..."), $this->ProductGroups(), GridFieldEditOriginalPageConfigWithDelete::create());
     return $gridField;
 }
 public function updateCMSFields(FieldList $fields)
 {
     $fields->removeFieldFromTab("Root", "DeliverySpecialChargedProducts");
     $fields->removeFieldFromTab("Root", "SpecialPricePostalCodes");
     $fields->addFieldsToTab("Root.Delivery", array(new TextField("DeliveryChargeTitle", "Delivery Charge Title"), new CurrencyField("PriceWithoutApplicableProducts", "Standard Delivery Charge without Special Products in order"), new CurrencyField("PriceWithApplicableProducts", "Standard Delivery Charge with Special Products in order"), new GridField("DeliverySpecialChargedProducts", "Products with special Delivery Charge", $this->owner->DeliverySpecialChargedProducts(), GridFieldEditOriginalPageConfigWithDelete::create()), new GridField("SpecialPricePostalCodes", "Special Price Postal Codes", $this->owner->SpecialPricePostalCodes(), GridFieldConfig_RelationEditor::create())));
 }
 /**
  * Standard SS method
  * @return FieldSet
  */
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->addFieldToTab("Root.Images", new CheckboxField("HasImages", _t("ProductQuestion.HAS_IMAGES", "This question makes use of images")));
     if (!$this->HasImages) {
         $fields->addFieldToTab("Root.DefaultFormField", new OptionSetField("DefaultFormField", _t("ProductQuestion.DEFAULTFORMFIELD", "Field type to use"), $this->Options ? $this->Config()->get("available_form_fields_list") : $this->Config()->get("available_form_fields_free")));
     } else {
         $fields->removeFieldFromTab("Root.Main", "DefaultFormField");
     }
     $productFieldTitle = _t("ProductQuestion.PRODUCTS", "Products showing this question");
     if ($this->ApplyToAllProducts) {
         $productField = new HiddenField("ProductsToIgnore");
     } elseif (Product::get()->count() < $this->Config()->get("max_products_for_checkbox_set_field")) {
         $productField = new CheckboxSetField("Products", $productFieldTitle, Product::get()->map("ID", "FullName")->toArray());
     } else {
         $productField = new GridField('Products', _t("ProductQuestion.PRODUCTS", "Products showing this question"), $this->Products(), GridFieldEditOriginalPageConfigWithDelete::create());
     }
     $fields->addFieldToTab("Root.Products", $productField);
     if (!$this->ApplyToAllProducts) {
         foreach ($this->Products() as $product) {
             $fields->addFieldToTab("Root.Products", new LiteralField("Product" . $product->ID, "<h5><a href=\"" . $product->CMSEditLink() . "\">" . _t("ProductQuestion.BACK_TO", "Edit ") . " " . $product->Title . "</a></h5>"));
         }
     }
     if ($this->HasImages) {
         $folders = Folder::get();
         if ($folders->count()) {
             $folderMap = $folders->map("ID", "Title")->toArray();
             $folders = null;
             $fields->removeFieldFromTab("Root.Main", "Folder");
             $fields->addFieldToTab("Root.Images", $treeDropdownField = new TreeDropdownField("FolderID", _t("ProductQuestion.FOLDER", "Folder"), "Folder"));
             $treeDropdownFieldRightTitle = _t("ProductQuestion.FOLDER_ID", "Select the folder in which the images live.\n\t\t\t\t\t<br />\n\t\t\t\t\t<strong>\n\t\t\t\t\t\tThe images need to have the exact same file name as the options listed.\n\t\t\t\t\t\tFor example, if one of your options is 'red' then there should be a file in your folder called 'red.png' or 'red.jpg' or 'red.gif',\n\t\t\t\t\t\tthe following filenames would not work: 'Red.png', 'red1.jpg', 'RED.gif', etc...\n\t\t\t\t\t</strong>");
             $folder = Folder::get()->byID($this->FolderID);
             if ($folder) {
                 $treeDropdownFieldRightTitle .= "\n\t\t\t\t\t\t<br /><a href=\"admin/assets/show/" . $folder->ID . "/\">" . _t("ProductQuestion.OPEN", "Open") . " " . $folder->Title . "</a>\n\t\t\t\t\t\t<br /><a href=\"admin/assets/add/?ID" . $folder->ID . "/\">" . _t("ProductQuestion.ADD_IMAGES_TO", "Add images to") . " " . $folder->Title . "</a>";
             }
             $treeDropdownField->setRightTitle($treeDropdownFieldRightTitle);
         }
         if ($this->FolderID) {
             $imagesInFolder = Image::get()->filter(array("ParentID" => $this->FolderID));
             if ($imagesInFolder->count()) {
                 $imagesInFolderArray = $imagesInFolder->map("ID", "Name")->toArray();
                 $options = explode(",", $this->Options);
                 $imagesInFolderField = new ReadonlyField("ImagesInFolder", _t("ProductQuestion.NO_IMAGES", "Images in folder"), implode("<br />", $imagesInFolderArray));
                 $imagesInFolderField->dontEscape = true;
                 $fields->addFieldToTab("Root.Images", $imagesInFolderField);
                 //matches
                 if ($this->exists()) {
                     $matchesInFolderArray = array();
                     $nonMatchesInFolderArray = array();
                     $options = explode(",", $this->Options);
                     if (count($options)) {
                         foreach ($options as $option) {
                             $fileNameArray = self::create_file_array_from_option($option);
                             foreach ($fileNameArray as $fileName) {
                                 if (in_array($fileName, $imagesInFolderArray)) {
                                     $matchesInFolderArray[$option] = "<strong>" . $option . "</strong>: " . $fileName;
                                 }
                             }
                             if (!isset($matchesInFolderArray[$option])) {
                                 $nonMatchesInFolderArray[$option] = "<strong>" . $option . " - add one these files: </strong>" . implode(",", $fileNameArray);
                             }
                         }
                     }
                     $matchesInFolderField = new ReadonlyField("MatchesInFolder", _t("ProductQuestion.MATCHES_IN_FOLDER", "Matches in folder"), implode("<br />", $matchesInFolderArray));
                     $matchesInFolderField->dontEscape = true;
                     $fields->addFieldToTab("Root.Images", $matchesInFolderField);
                     $nonMatchesInFolderField = new ReadonlyField("NonMatchesInFolder", _t("ProductQuestion.NON_MATCHES_IN_FOLDER", "NON Matches in folder"), implode("<br />", $nonMatchesInFolderArray));
                     $nonMatchesInFolderField->dontEscape = true;
                     $fields->addFieldToTab("Root.Images", $nonMatchesInFolderField);
                 }
             } else {
                 $imagesInFolderField = new ReadonlyField("ImagesInFolder", "Images in folder", _t("ProductQuestion.NO_IMAGES", "There are no images in this folder"));
                 $fields->addFieldToTab("Root.Main", $imagesInFolderField);
             }
         }
     } else {
         $fields->removeByName("Folder");
     }
     if ($this->Products()->count()) {
         $randomProduct = $this->Products()->First();
         $fields->addFieldToTab("Root.Example", $this->getFieldForProduct($randomProduct));
     }
     $folderExplanation = _t("ProductQuestion.FOLDER_EXPLANATION", "Tick the box to link each option to an image (e.g. useful if you have colour swatches).\n\t\t\t\tOnce ticked and the question is saved you will be able to select a folder from where to select the images.");
     $field = $fields->dataFieldByName("HasImages");
     if ($field) {
         $field->setDescription($folderExplanation);
     }
     $this->extend('updateCMSFields', $fields);
     //custom field labels
     $internalCodeField = $fields->dataFieldByName("InternalCode");
     $internalCodeField->setRightTitle(_t("ProductQuestion.INTERNALCODE", "Code used to identify question (not shown to customers)"));
     $questionField = $fields->dataFieldByName("Question");
     $questionField->setRightTitle(_t("ProductQuestion.QUESTION", "Question (e.g. what configuration do you prefer?)"));
     $labelField = $fields->dataFieldByName("Label");
     $labelField->setRightTitle(_t("ProductQuestion.LABEL", "Label (e.g. Your selected configuration)"));
     $defaultAnswerField = $fields->dataFieldByName("DefaultAnswer");
     $defaultAnswerField->setRightTitle(_t("ProductQuestion.DEFAULT_ANSWER", "Default Answer if no Answer has been provided.  Can be blank or, for example, tba."));
     $optionsField = $fields->dataFieldByName("Options");
     $optionsField->setRightTitle(_t("ProductQuestion.OPTIONS", "Predefined Options (leave blank for any option).  These must be comma separated (e.g. red, blue, yellow, orange)"));
     return $fields;
 }
 /**
  * standard SS method
  *
  */
 function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fieldLabels = $this->Config()->get("field_labels_right");
     foreach ($fields->dataFields() as $field) {
         $name = $field->getName();
         if (isset($fieldLabels[$name])) {
             $field->setDescription($fieldLabels[$name]);
         }
     }
     if ($this->ApplyEvenWithoutCode) {
         $fields->removeFieldsFromTab("Root.Main", array('Code', 'MaximumDiscount', 'MinimumOrderSubTotalValue'));
     }
     if ($this->ApplyPercentageToApplicableProducts) {
         $fields->removeFieldsFromTab("Root.Main", array('DiscountAbsolute'));
     }
     $fields->addFieldToTab("Root.Main", new ReadonlyField("UseCount", self::$field_labels["UseCount"]));
     $fields->addFieldToTab("Root.Main", new ReadonlyField("IsValidNice", self::$field_labels["IsValidNice"]));
     if ($gridField1 = $fields->dataFieldByName("Products")) {
         $gridField1->setConfig(GridFieldEditOriginalPageConfigWithDelete::create());
     }
     if ($gridField2 = $fields->dataFieldByName("ProductGroups")) {
         $gridField2->setConfig(GridFieldEditOriginalPageConfigWithDelete::create());
     }
     if ($gridField3 = $fields->dataFieldByName("ProductGroupsMustAlsoBePresentIn")) {
         $gridField3->setConfig(GridFieldEditOriginalPageConfigWithDelete::create());
     }
     return $fields;
 }