Fluent::domain_for_locale PHP Method

domain_for_locale() public static method

Determine the home domain for this locale
public static domain_for_locale ( string $locale )
$locale string
    public static function domain_for_locale($locale)
    {
        foreach (self::domains() as $domain => $config) {
            if (!empty($config['locales']) && in_array($locale, $config['locales'])) {
                return $domain;
            }
        }
    }

Usage Example

コード例 #1
0
 public function updateRelativeLink(&$base, &$action)
 {
     // Don't inject locale to subpages
     if ($this->owner->ParentID && SiteTree::config()->nested_urls) {
         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;
         }
         // 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);
 }
All Usage Examples Of Fluent::domain_for_locale