public function getCMSFields()
 {
     // Get a list of available product classes
     $classnames = ClassInfo::getValidSubClasses("CatalogueCategory");
     $categories_array = array();
     foreach ($classnames as $classname) {
         $description = Config::inst()->get($classname, 'description');
         if ($classname == 'CatalogueCategory' && !$description) {
             $description = self::config()->description;
         }
         $description = $description ? $classname . ' - ' . $description : $classname;
         $categories_array[$classname] = $description;
     }
     if (!$this->ID) {
         $controller = Controller::curr();
         $parent_id = $controller->request->getVar("ParentID");
         $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', HiddenField::create("Title")->setValue(_t("Catalogue.NewCategory", "New Category")), HiddenField::create("ParentID")->setValue($parent_id), ProductTypeField::create("ClassName", _t("Catalogue.SelectCategoryType", "Select a type of Category"), $categories_array))));
     } else {
         // If CMS Installed, use URLSegmentField, otherwise use text
         // field for URL
         if (class_exists('SiteTreeURLSegmentField')) {
             $baseLink = Controller::join_links(Director::absoluteBaseURL());
             $url_field = SiteTreeURLSegmentField::create("URLSegment");
             $url_field->setURLPrefix($baseLink);
         } else {
             $url_field = TextField::create("URLSegment");
         }
         $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', TextField::create("Title", $this->fieldLabel('Title')), $url_field, TreeDropdownField::create('ParentID', _t('CatalogueAdmin.ParentCategory', 'Parent Category'), 'CatalogueCategory')->setLabelField("Title"), ToggleCompositeField::create('Metadata', _t('CatalogueAdmin.MetadataToggle', 'Metadata'), array($metaFieldDesc = TextareaField::create("MetaDescription", $this->fieldLabel('MetaDescription')), $metaFieldExtra = TextareaField::create("ExtraMeta", $this->fieldLabel('ExtraMeta'))))->setHeadingLevel(4)), $tabSettings = new Tab('Settings', DropdownField::create("ClassName", _t("CatalogueAdmin.CategoryType", "Type of Category"), $categories_array))));
         // Help text for MetaData on page content editor
         $metaFieldDesc->setRightTitle(_t('CatalogueAdmin.MetaDescHelp', "Search engines use this content for displaying search results (although it will not influence their ranking)."))->addExtraClass('help');
         $metaFieldExtra->setRightTitle(_t('CatalogueAdmin.MetaExtraHelp', "HTML tags for additional meta information. For example <meta name=\"customName\" content=\"your custom content here\" />"))->addExtraClass('help');
         $fields->addFieldToTab('Root.Products', GridField::create("Products", "", $this->Products(), GridFieldConfig_RelationEditor::create()->addComponent(new GridFieldOrderableRows('SortOrder'))));
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
 public function getCMSFields()
 {
     // Get a list of available product classes
     $classnames = ClassInfo::getValidSubClasses("CatalogueProduct");
     $product_array = array();
     foreach ($classnames as $classname) {
         if ($classname != "CatalogueProduct") {
             $description = Config::inst()->get($classname, 'description');
             if ($classname == 'Product' && !$description) {
                 $description = self::config()->description;
             }
             $description = $description ? $classname . ' - ' . $description : $classname;
             $product_array[$classname] = $description;
         }
     }
     // If we are creating a product, let us choose the product type
     if (!$this->ID) {
         $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', HiddenField::create("Title")->setValue(_t("Catalogue.NewProduct", "New Product")), ProductTypeField::create("ClassName", _t("Catalogue.SelectProductType", "Select a type of Product"), $product_array))));
     } else {
         // If CMS Installed, use URLSegmentField, otherwise use text
         // field for URL
         if (class_exists('SiteTreeURLSegmentField')) {
             $baseLink = Controller::join_links(Director::absoluteBaseURL());
             $url_field = SiteTreeURLSegmentField::create("URLSegment");
             $url_field->setURLPrefix($baseLink);
         } else {
             $url_field = TextField::create("URLSegment");
         }
         $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', TextField::create("Title", $this->fieldLabel('Title')), $url_field, HTMLEditorField::create('Content', $this->fieldLabel('Content'))->setRows(20)->addExtraClass('stacked'), ToggleCompositeField::create('Metadata', _t('CatalogueAdmin.MetadataToggle', 'Metadata'), array($metaFieldDesc = TextareaField::create("MetaDescription", $this->fieldLabel('MetaDescription')), $metaFieldExtra = TextareaField::create("ExtraMeta", $this->fieldLabel('ExtraMeta'))))->setHeadingLevel(4)), $tabSettings = new Tab('Settings', NumericField::create("BasePrice", _t("Catalogue.Price", "Price")), TextField::create("StockID", $this->fieldLabel('StockID'))->setRightTitle(_t("Catalogue.StockIDHelp", "For example, a product SKU")), DropdownField::create("TaxRateID", $this->fieldLabel('TaxRate'), TaxRate::get()->map())->setEmptyString(_t("Catalogue.None", "None")), TreeMultiSelectField::create("Categories", null, "CatalogueCategory"), CheckboxField::create("Disabled", _t("Catalogue.DisableProduct", "Disable this product (will not appear on shopfront)")), DropdownField::create("ClassName", _t("CatalogueAdmin.ProductType", "Type of product"), $product_array)), $tabImages = new Tab('Images', SortableUploadField::create('Images', $this->fieldLabel('Images'), $this->Images()))));
         // Help text for MetaData on page content editor
         $metaFieldDesc->setRightTitle(_t('CatalogueAdmin.MetaDescHelp', "Search engines use this content for displaying search results (although it will not influence their ranking)."))->addExtraClass('help');
         $metaFieldExtra->setRightTitle(_t('CatalogueAdmin.MetaExtraHelp', "HTML tags for additional meta information. For example <meta name=\"customName\" content=\"your custom content here\" />"))->addExtraClass('help');
         $fields->addFieldToTab('Root.Related', GridField::create('RelatedProducts', "", $this->RelatedProducts(), GridFieldConfig_RelationEditor::create()));
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }