Beispiel #1
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;
 }
    /**
     * 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;
    }
Beispiel #3
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;
	}