Source of file ExtraTable_FluentSiteTree.php
Size: 4,034 Bytes - Last Modified: 2021-12-24T05:18:20+00:00
/var/www/docs.ssmods.com/process/src/code/extensions/ExtraTable_FluentSiteTree.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 | <?php /** * All functions are copied from fluent module > FluentSiteTree.php * * @package fluent-extra * @author Jason Zhang <jason.zhang@internetrix.com.au> */ class ExtraTable_FluentSiteTree extends ExtraTable_FluentExtension { public function MetaTags(&$tags) { if(Fluent::config()->perlang_persite){ $tags .= $this->owner->renderWith('FluentSiteTree_MetaTags'); } } public function onBeforeWrite() { // Fix issue with MenuTitle not containing the correct translated value // Unless it's a virtualpage if (! ($this->owner instanceof VirtualPage) ) { $this->owner->setField('MenuTitle', $this->owner->MenuTitle); } parent::onBeforeWrite(); } /** * Ensure that the controller is correctly initialised * * @param ContentController $controller */ public function contentcontrollerInit($controller) { Fluent::install_locale(); } public function updateRelativeLink(&$base, &$action) { if(Director::is_absolute_url($base)) return; if ( // Don't inject locale to subpages ($this->owner->ParentID && SiteTree::config()->nested_urls) && // add compatibility with Multisites !(class_exists('Site') && in_array($this->owner->ParentID, Site::get()->getIDList())) ) { return; } // For blank/temp pages such as Security controller fallback to querystring $locale = Fluent::current_locale(); if (!$this->owner->exists()) { $base = Controller::join_links($base, '?'.Fluent::config()->query_param.'='.urlencode($locale)); return; } // Check if this locale is the default for its own domain $domain = Fluent::domain_for_locale($locale); if ($locale === Fluent::default_locale($domain)) { // For home page in the default locale, do not alter home url if ($base === null) { return; } // If default locale shouldn't have prefix, then don't add prefix if (Fluent::disable_default_prefix()) { return; } // For all pages on a domain where there is only a single locale, // then the domain itself is sufficient to distinguish that domain // See https://github.com/tractorcow/silverstripe-fluent/issues/75 $domainLocales = Fluent::locales($domain); if (count($domainLocales) === 1) { return; } } // Simply join locale root with base relative URL $localeURL = Fluent::alias($locale); $base = Controller::join_links($localeURL, $base); } public function LocaleLink($locale) { // For blank/temp pages such as Security controller fallback to querystring if (!$this->owner->exists()) { $url = Controller::curr()->getRequest()->getURL(); return Controller::join_links($url, '?'.Fluent::config()->query_param.'='.urlencode($locale)); } return parent::LocaleLink($locale); } /** * @param FieldList $fields */ public function updateCMSFields(FieldList $fields) { parent::updateCMSFields($fields); // Fix URLSegment field issue for root pages if (!SiteTree::config()->nested_urls || empty($this->owner->ParentID)) { $baseUrl = Director::baseURL(); if (class_exists('Subsite') && $this->owner->SubsiteID) { $baseUrl = Director::protocol() . $this->owner->Subsite()->domain() . '/'; } $baseLink = Director::absoluteURL(Controller::join_links( $baseUrl, Fluent::alias(Fluent::current_locale()), '/' )); $urlsegment = $fields->dataFieldByName('URLSegment'); $urlsegment->setURLPrefix($baseLink); } } } |