public function getURLPrefix()
 {
     $url = parent::getURLPrefix();
     if (Director::isDev() || Director::isTest()) {
         $urlarray = parse_url($url);
         // define override
         if (defined('DEV_SUBSITE_' . Subsite::currentSubsiteID())) {
             $subsiteurl = 'DEV_SUBSITE_' . Subsite::currentSubsiteID();
             return constant($subsiteurl) . $urlarray['path'];
         }
         if (!Subsite::currentSubsite() instanceof Subsite) {
             return $url;
         }
         // if set in config settings
         $currentDomain = Subsite::currentSubsite()->getPrimarySubsiteDomain();
         if (Director::isTest()) {
             $currentDomain = Subsite::currentSubsite()->TestDomainID ? Subsite::currentSubsite()->TestDomain() : $currentDomain;
         }
         if (Director::isDev()) {
             $currentDomain = Subsite::currentSubsite()->DevDomainID ? Subsite::currentSubsite()->DevDomain() : $currentDomain;
         }
         if (!$currentDomain) {
             return $url;
         }
         return $currentDomain->getFullProtocol() . $currentDomain->Domain . $urlarray['path'];
     }
     return $url;
 }
Ejemplo n.º 2
0
 public function updateCMSFields(FieldList $fields)
 {
     if ($this->owner->ID) {
         $uf = SiteTreeURLSegmentField::create("URLSegment", "URL Segment");
         $uf->setURLPrefix(Director::BaseURL() . $this->getURLPrefix());
         $fields->addFieldToTab("Root.Main", $uf, "Title");
     } else {
         $fields->removeByName("URLSegment");
     }
 }
    /**
     * Overload getCMSFields for our custom fields
     *
     * @return FieldList The list of CMS Fields
     */
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        //Add the status/view link
        if ($this->ID) {
            if ($this->isVersioned) {
                $status = $this->getStatus();
                $color = '#E88F31';
                $links = sprintf("<a target=\"_blank\" class=\"ss-ui-button\" data-icon=\"preview\" href=\"%s\">%s</a>", $this->Link() . '?stage=Stage', 'Draft');
                if ($status == 'Published') {
                    $color = '#000';
                    $links .= sprintf("<a target=\"_blank\" class=\"ss-ui-button\" data-icon=\"preview\" href=\"%s\">%s</a>", $this->Link() . '?stage=Live', 'Published');
                    if ($this->hasChangesOnStage()) {
                        $status .= ' (changed)';
                        $color = '#428620';
                    }
                }
                $statusPill = '<h3 class="doapTitle" style="background: ' . $color . ';">' . $status . '</h3>';
            } else {
                $links = sprintf("<a target=\"_blank\" class=\"ss-ui-button\" data-icon=\"preview\" href=\"%s\">%s</a>", $this->Link() . '?stage=Stage', 'View');
                $statusPill = "";
            }
            $fields->addFieldToTab('Root.Main', new LiteralField('', '<div class="doapToolbar">
					' . $statusPill . '
					<p class="doapViewLinks">
						' . $links . '
					</p>
				</div>'));
        }
        //Remove Scafolded fields
        $fields->removeFieldFromTab('Root.Main', 'URLSegment');
        $fields->removeFieldFromTab('Root.Main', 'Status');
        $fields->removeFieldFromTab('Root.Main', 'Version');
        $fields->removeFieldFromTab('Root.Main', 'MetaTitle');
        $fields->removeFieldFromTab('Root.Main', 'MetaDescription');
        $fields->removeByName('Versions');
        $fields->addFieldToTab('Root.Main', new TextField('Title'));
        if ($this->ID) {
            $urlsegment = new SiteTreeURLSegmentField("URLSegment", $this->fieldLabel('URLSegment'));
            if ($this->getListingPage()) {
                $prefix = $this->getListingPage()->AbsoluteLink('show') . '/';
            } else {
                $prefix = Director::absoluteBaseURL() . 'listing-page/show/';
            }
            $urlsegment->setURLPrefix($prefix);
            $helpText = _t('SiteTreeURLSegmentField.HelpChars', ' Special characters are automatically converted or removed.');
            $urlsegment->setHelpText($helpText);
            $fields->addFieldToTab('Root.Main', $urlsegment);
        }
        $fields->addFieldToTab('Root.Main', new HTMLEditorField('Content'));
        $fields->addFieldToTab('Root.Main', new ToggleCompositeField('Metadata', 'Metadata', array(new TextField("MetaTitle", $this->fieldLabel('MetaTitle')), new TextareaField("MetaDescription", $this->fieldLabel('MetaDescription')))));
        //$fields->push(new HiddenField('PreviewURL', 'Preview URL', $this->StageLink()));
        //$fields->push(new TextField('CMSEditURL', 'Preview URL', $this->CMSEditLink()));
        return $fields;
    }
 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 &lt;meta name=\"customName\" content=\"your custom content here\" /&gt;"))->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 = array_values(ClassInfo::subclassesFor("Product"));
     $product_types = array();
     foreach ($classnames as $classname) {
         $instance = singleton($classname);
         $product_types[$classname] = $instance->i18n_singular_name();
     }
     // 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"), DropdownField::create("ClassName", _t("CatalogueAdmin.ProductType", "Type of product"), $product_types))));
     // 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 &lt;meta name=\"customName\" content=\"your custom content here\" /&gt;"))->addExtraClass('help');
     if ($this->ID) {
         $fields->addFieldToTab('Root.Images', SortableUploadField::create('Images', $this->fieldLabel('Images'), $this->Images()));
         $fields->addFieldToTab('Root.Related', GridField::create('RelatedProducts', "", $this->RelatedProducts(), new GridFieldConfig_CatalogueRelated("Product", null, 'SortOrder')));
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
Ejemplo n.º 6
0
 /**
  * Returns a FieldList with which to create the main editing form.
  *
  * You can override this in your child classes to add extra fields - first get the parent fields using
  * parent::getCMSFields(), then use addFieldToTab() on the FieldList.
  *
  * See {@link getSettingsFields()} for a different set of fields concerned with configuration aspects on the record,
  * e.g. access control.
  *
  * @return FieldList The fields to be displayed in the CMS
  */
 public function getCMSFields()
 {
     require_once "forms/Form.php";
     // Status / message
     // Create a status message for multiple parents
     if ($this->ID && is_numeric($this->ID)) {
         $linkedPages = $this->VirtualPages();
         $parentPageLinks = array();
         if ($linkedPages->Count() > 0) {
             foreach ($linkedPages as $linkedPage) {
                 $parentPage = $linkedPage->Parent;
                 if ($parentPage) {
                     if ($parentPage->ID) {
                         $parentPageLinks[] = "<a class=\"cmsEditlink\" href=\"admin/pages/edit/show/{$linkedPage->ID}\">{$parentPage->Title}</a>";
                     } else {
                         $parentPageLinks[] = "<a class=\"cmsEditlink\" href=\"admin/pages/edit/show/{$linkedPage->ID}\">" . _t('SiteTree.TOPLEVEL', 'Site Content (Top Level)') . "</a>";
                     }
                 }
             }
             $lastParent = array_pop($parentPageLinks);
             $parentList = "'{$lastParent}'";
             if (count($parentPageLinks) > 0) {
                 $parentList = "'" . implode("', '", $parentPageLinks) . "' and " . $parentList;
             }
             $statusMessage[] = _t('SiteTree.APPEARSVIRTUALPAGES', "This content also appears on the virtual pages in the {title} sections.", array('title' => $parentList));
         }
     }
     if ($this->HasBrokenLink || $this->HasBrokenFile) {
         $statusMessage[] = _t('SiteTree.HASBROKENLINKS', "This page has broken links.");
     }
     $dependentNote = '';
     $dependentTable = new LiteralField('DependentNote', '<p></p>');
     // Create a table for showing pages linked to this one
     $dependentPages = $this->DependentPages();
     $dependentPagesCount = $dependentPages->Count();
     if ($dependentPagesCount) {
         $dependentColumns = array('Title' => $this->fieldLabel('Title'), 'AbsoluteLink' => _t('SiteTree.DependtPageColumnURL', 'URL'), 'DependentLinkType' => _t('SiteTree.DependtPageColumnLinkType', 'Link type'));
         if (class_exists('Subsite')) {
             $dependentColumns['Subsite.Title'] = singleton('Subsite')->i18n_singular_name();
         }
         $dependentNote = new LiteralField('DependentNote', '<p>' . _t('SiteTree.DEPENDENT_NOTE', 'The following pages depend on this page. This includes virtual pages, redirector pages, and pages with content links.') . '</p>');
         $dependentTable = GridField::create('DependentPages', false, $dependentPages);
         $dependentTable->getConfig()->getComponentByType('GridFieldDataColumns')->setDisplayFields($dependentColumns)->setFieldFormatting(array('Title' => function ($value, &$item) {
             return sprintf('<a href="admin/pages/edit/show/%d">%s</a>', (int) $item->ID, Convert::raw2xml($item->Title));
         }, 'AbsoluteLink' => function ($value, &$item) {
             return sprintf('<a href="%s" target="_blank">%s</a>', Convert::raw2xml($value), Convert::raw2xml($value));
         }));
     }
     $baseLink = Controller::join_links(Director::absoluteBaseURL(), self::config()->nested_urls && $this->ParentID ? $this->Parent()->RelativeLink(true) : null);
     $urlsegment = new SiteTreeURLSegmentField("URLSegment", $this->fieldLabel('URLSegment'));
     $urlsegment->setURLPrefix($baseLink);
     $helpText = self::config()->nested_urls && count($this->Children()) ? $this->fieldLabel('LinkChangeNote') : '';
     if (!Config::inst()->get('URLSegmentFilter', 'default_allow_multibyte')) {
         $helpText .= $helpText ? '<br />' : '';
         $helpText .= _t('SiteTreeURLSegmentField.HelpChars', ' Special characters are automatically converted or removed.');
     }
     $urlsegment->setHelpText($helpText);
     $fields = new FieldList($rootTab = new TabSet("Root", $tabMain = new Tab('Main', new TextField("Title", $this->fieldLabel('Title')), $urlsegment, new TextField("MenuTitle", $this->fieldLabel('MenuTitle')), $htmlField = new HtmlEditorField("Content", _t('SiteTree.HTMLEDITORTITLE', "Content", 'HTML editor title')), ToggleCompositeField::create('Metadata', _t('SiteTree.MetadataToggle', 'Metadata'), array($metaFieldDesc = new TextareaField("MetaDescription", $this->fieldLabel('MetaDescription')), $metaFieldExtra = new TextareaField("ExtraMeta", $this->fieldLabel('ExtraMeta'))))->setHeadingLevel(4)), $tabDependent = new Tab('Dependent', $dependentNote, $dependentTable)));
     $htmlField->addExtraClass('stacked');
     // Help text for MetaData on page content editor
     $metaFieldDesc->setRightTitle(_t('SiteTree.METADESCHELP', "Search engines use this content for displaying search results (although it will not influence their ranking)."))->addExtraClass('help');
     $metaFieldExtra->setRightTitle(_t('SiteTree.METAEXTRAHELP', "HTML tags for additional meta information. For example &lt;meta name=\"customName\" content=\"your custom content here\" /&gt;"))->addExtraClass('help');
     // Conditional dependent pages tab
     if ($dependentPagesCount) {
         $tabDependent->setTitle(_t('SiteTree.TABDEPENDENT', "Dependent pages") . " ({$dependentPagesCount})");
     } else {
         $fields->removeFieldFromTab('Root', 'Dependent');
     }
     $tabMain->setTitle(_t('SiteTree.TABCONTENT', "Main Content"));
     if ($this->ObsoleteClassName) {
         $obsoleteWarning = _t('SiteTree.OBSOLETECLASS', "This page is of obsolete type {type}. Saving will reset its type and you may lose data", array('type' => $this->ObsoleteClassName));
         $fields->addFieldToTab("Root.Main", new LiteralField("ObsoleteWarningHeader", "<p class=\"message warning\">{$obsoleteWarning}</p>"), "Title");
     }
     if (file_exists(BASE_PATH . '/install.php')) {
         $fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader", "<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING", "Warning: You should remove install.php from this SilverStripe install for security reasons.") . "</p>"), "Title");
     }
     // Backwards compat: Rewrite nested "Content" tabs to toplevel
     $fields->setTabPathRewrites(array('/^Root\\.Content\\.Main$/' => 'Root.Main', '/^Root\\.Content\\.([^.]+)$/' => 'Root.\\1'));
     if (self::$runCMSFieldsExtensions) {
         $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 &lt;meta name=\"customName\" content=\"your custom content here\" /&gt;"))->addExtraClass('help');
         $fields->addFieldToTab('Root.Related', GridField::create('RelatedProducts', "", $this->RelatedProducts(), GridFieldConfig_RelationEditor::create()));
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
Ejemplo n.º 8
0
	/**
	 * Returns a FieldList with which to create the main editing form.
	 *
	 * You can override this in your child classes to add extra fields - first
	 * get the parent fields using parent::getCMSFields(), then use
	 * addFieldToTab() on the FieldList.
	 * 
	 * See {@link getSettingsFields()} for a different set of fields
	 * concerned with configuration aspects on the record, e.g. access control
	 *
	 * @return FieldList The fields to be displayed in the CMS.
	 */
	function getCMSFields() {
		require_once("forms/Form.php");
		// Status / message
		// Create a status message for multiple parents
		if($this->ID && is_numeric($this->ID)) {
			$linkedPages = $this->VirtualPages();

			$parentPageLinks = array();

			if($linkedPages->Count() > 0) {
				foreach($linkedPages as $linkedPage) {
					$parentPage = $linkedPage->Parent;
					if($parentPage) {
						if($parentPage->ID) {
							$parentPageLinks[] = "<a class=\"cmsEditlink\" href=\"admin/show/$linkedPage->ID\">{$parentPage->Title}</a>";
						} else {
							$parentPageLinks[] = "<a class=\"cmsEditlink\" href=\"admin/show/$linkedPage->ID\">" .
								_t('SiteTree.TOPLEVEL', 'Site Content (Top Level)') .
								"</a>";
						}
					}
				}

				$lastParent = array_pop($parentPageLinks);
				$parentList = "'$lastParent'";

				if(count($parentPageLinks) > 0) {
					$parentList = "'" . implode("', '", $parentPageLinks) . "' and "
						. $parentList;
				}

				$statusMessage[] = sprintf(
					_t('SiteTree.APPEARSVIRTUALPAGES', "This content also appears on the virtual pages in the %s sections."),
					$parentList
				);
			}
		}

		if($this->HasBrokenLink || $this->HasBrokenFile) {
			$statusMessage[] = _t('SiteTree.HASBROKENLINKS', "This page has broken links.");
		}
		
		$dependentNote = '';
		$dependentTable = new LiteralField('DependentNote', '<p></p>');
		
		// Create a table for showing pages linked to this one
		$dependentPagesCount = $this->DependentPagesCount();
		if($dependentPagesCount) {
			$dependentColumns = array(
				'Title' => $this->fieldLabel('Title'),
				'AbsoluteLink' => _t('SiteTree.DependtPageColumnURL', 'URL'),
				'DependentLinkType' => _t('SiteTree.DependtPageColumnLinkType', 'Link type'),
			);
			if(class_exists('Subsite')) $dependentColumns['Subsite.Title'] = singleton('Subsite')->i18n_singular_name();
			
			$dependentNote = new LiteralField('DependentNote', '<p>' . _t('SiteTree.DEPENDENT_NOTE', 'The following pages depend on this page. This includes virtual pages, redirector pages, and pages with content links.') . '</p>');
			$dependentTable = new TableListField(
				'DependentPages',
				$this->DependentPages(),
				$dependentColumns
			);
			$dependentTable->setFieldFormatting(array(
				'Title' => '<a href=\"admin/show/$ID\">$Title</a>',
				'AbsoluteLink' => '<a href=\"$value\">$value</a>',
			));
			$dependentTable->setPermissions(array(
				'show',
				'export'
			));
		}
		
		$baseLink = Controller::join_links (
			Director::absoluteBaseURL(),
			(self::nested_urls() && $this->ParentID ? $this->Parent()->RelativeLink(true) : null)
		);
		
		
		
		$url = (strlen($baseLink) > 36) ? "..." .substr($baseLink, -32) : $baseLink;
		$urlsegment = new SiteTreeURLSegmentField("URLSegment", $this->fieldLabel('URLSegment'));
		$urlsegment->setURLPrefix($url);
		$urlsegment->setHelpText(self::nested_urls() && count($this->Children()) ? $this->fieldLabel('LinkChangeNote'): false);
		
		$fields = new FieldList(
			$rootTab = new TabSet("Root",
				$tabMain = new Tab('Main',
					new TextField("Title", $this->fieldLabel('Title')),
					new TextField("MenuTitle", $this->fieldLabel('MenuTitle')),
					$htmlField = new HtmlEditorField("Content", _t('SiteTree.HTMLEDITORTITLE', "Content", 'HTML editor title'))
				),
				$tabMeta = new Tab('Metadata',
					$urlsegment,
					new TextField("MetaTitle", $this->fieldLabel('MetaTitle')),
					new TextareaField("MetaKeywords", $this->fieldLabel('MetaKeywords'), 1),
					new TextareaField("MetaDescription", $this->fieldLabel('MetaDescription')),
					new TextareaField("ExtraMeta",$this->fieldLabel('ExtraMeta'))
				),
				$tabDependent = new Tab('Dependent',
					$dependentNote,
					$dependentTable
				)
			)
		);
		$htmlField->addExtraClass('stacked');
		
		// Conditional dependent pages tab
		if($dependentPagesCount) $tabDependent->setTitle(_t('SiteTree.TABDEPENDENT', "Dependent pages") . " ($dependentPagesCount)");
		else $fields->removeFieldFromTab('Root', 'Dependent');
		
		$tabMain->setTitle(_t('SiteTree.TABCONTENT', "Main Content"));
		$tabMeta->setTitle(_t('SiteTree.TABMETA', "Metadata"));

		if(file_exists(BASE_PATH . '/install.php')) {
			$fields->addFieldToTab("Root.Main", new LiteralField("InstallWarningHeader", 
				"<p class=\"message warning\">" . _t("SiteTree.REMOVE_INSTALL_WARNING", 
				"Warning: You should remove install.php from this SilverStripe install for security reasons.")
				. "</p>"), "Title");
		}

		
		if(self::$runCMSFieldsExtensions) {
			$this->extend('updateCMSFields', $fields);
		}

		return $fields;
	}
Ejemplo n.º 9
0
 /**
  * Set some CMS fields for managing Products
  * 
  * @see Page::getCMSFields()
  * @return FieldList
  */
 public function getCMSFields()
 {
     $shopConfig = ShopConfig::current_shop_config();
     $fields = parent::getCMSFields();
     //Main Product Image
     $fields->addFieldToTab("Root.Main", $uploadField = new UploadField("MainProductImage", "Main Product Image"));
     $uploadField->setFolderName('Store');
     $uploadField->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
     // Use SortableUploadField instead of UploadField!
     $imageField = new SortableUploadField('OtherImages', 'Other Product Images');
     $imageField->setFolderName('Store');
     $imageField->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
     $fields->addFieldToTab('Root.Main', $imageField);
     //Product fields
     $fields->addFieldToTab('Root.Main', new PriceField('Price'), 'Content');
     //Replace URL Segment field
     if ($this->ParentID == -1) {
         $urlsegment = new SiteTreeURLSegmentField("URLSegment", 'URLSegment');
         $baseLink = Controller::join_links(Director::absoluteBaseURL(), 'product/');
         $url = strlen($baseLink) > 36 ? "..." . substr($baseLink, -32) : $baseLink;
         $urlsegment->setURLPrefix($url);
         $fields->replaceField('URLSegment', $urlsegment);
     }
     if ($this->isInDB()) {
         //Product attributes
         $listField = new GridField('Attributes', 'Attributes', $this->Attributes(), GridFieldConfig_BasicSortable::create());
         $fields->addFieldToTab('Root.Attributes', $listField);
         //Product variations
         $attributes = $this->Attributes();
         if ($attributes && $attributes->exists()) {
             //Remove the stock level field if there are variations, each variation has a stock field
             $fields->removeByName('Stock');
             $variationFieldList = array();
             foreach ($attributes as $attribute) {
                 $variationFieldList['AttributeValue_' . $attribute->ID] = $attribute->Title;
             }
             $variationFieldList = array_merge($variationFieldList, singleton('Variation')->summaryFields());
             $config = GridFieldConfig_HasManyRelationEditor::create();
             $dataColumns = $config->getComponentByType('GridFieldDataColumns');
             $dataColumns->setDisplayFields($variationFieldList);
             $listField = new GridField('Variations', 'Variations', $this->Variations(), $config);
             $fields->addFieldToTab('Root.Variations', $listField);
         }
     }
     //Ability to edit fields added to CMS here
     $this->extend('updateProductCMSFields', $fields);
     if ($warning = ShopConfig::base_currency_warning()) {
         $fields->addFieldToTab('Root.Main', new LiteralField('BaseCurrencyWarning', '<p class="message warning">' . $warning . '</p>'), 'Title');
     }
     return $fields;
 }