If viewing in the CMS items filtered by locale will always be visible, but in the frontend will be filtered
as expected.
For the sake of unit tests Fluent assumes a frontend execution environment.
public static is_frontend ( boolean $ignoreController = false ) : boolean | ||
$ignoreController | boolean | Flag to indicate whether the current controller should be ignored, and detection should be performed by inspecting the URL. Used for testing. Defaults to false. |
리턴 | boolean | Flag indicating if the translation should act on the frontend |
/** * Gets the current locale * * @param boolean $persist Attempt to persist any detected locale within session / cookies * @return string i18n locale code */ public static function current_locale($persist = true) { // Check overridden locale if (self::$_override_locale) { return self::$_override_locale; } // Check direct request $locale = self::get_request_locale(); // Persistant variables if (empty($locale)) { $locale = self::get_persist_locale(); } // Check browser headers if (empty($locale)) { $locale = self::detect_browser_locale(); } // Fallback to default if empty or invalid (for this domain) $caresAboutDomains = Fluent::is_frontend(); if (empty($locale) || !in_array($locale, self::locales($caresAboutDomains))) { $locale = self::default_locale($caresAboutDomains); } // Persist locale if requested if ($persist) { self::set_persist_locale($locale); } return $locale; }
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) { if (!FluentOldPageRedirectFix::$disableSkipIDFilter) { // Skip ID based filters if ($query->filtersOnID()) { return; } } // Skip filter in the CMS, unless filtering is explicitly turned on $filterAdmin = $dataQuery->getQueryParam('Fluent.FilterAdmin'); if (!$filterAdmin) { $isFrontend = $dataQuery->getQueryParam('Fluent.IsFrontend'); if ($isFrontend === null) { $isFrontend = Fluent::is_frontend(); } if (!$isFrontend) { return; } } // Add filter for locale $locale = $dataQuery->getQueryParam('Fluent.Locale') ?: Fluent::current_locale(); $query->addWhere("\"{$this->ownerBaseClass}\".\"LocaleFilter_{$locale}\" = 1"); }
/** * Amend freshly created DataQuery objects with the current locale and frontend status * * @param SQLQuery * @param DataQuery */ public function augmentDataQueryCreation(SQLQuery $query, DataQuery $dataQuery) { $dataQuery->setQueryParam('Fluent.Locale', Fluent::current_locale()); $dataQuery->setQueryParam('Fluent.IsFrontend', Fluent::is_frontend()); }
public function testIsFrontendIgnorance() { $this->withController(new FluentTest_ContentController(), function ($test) { $test->assertTrue(Fluent::is_frontend()); }); }
public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) { // Skip ID based filters if ($query->filtersOnID()) { return; } // Skip filter in the CMS $isFrontend = $dataQuery->getQueryParam('Fluent.IsFrontend'); if ($isFrontend === null) { $isFrontend = Fluent::is_frontend(); } if (!$isFrontend) { return; } // Add filter for locale $locale = $dataQuery->getQueryParam('Fluent.Locale') ?: Fluent::current_locale(); $query->addWhere("\"{$this->ownerBaseClass}\".\"LocaleFilter_{$locale}\" = 1"); }