TractorCow\Fluent\Middleware\DetectLocaleMiddleware
DetectLocaleMiddleware will detect if a locale has been requested (or is default) and is not the current locale, and will redirect the user to that locale if needed.
Will cascade through different checks in order, see "configuration" docs for details.
Additionally, detected locales will be set in session and cookies.
Synopsis
class DetectLocaleMiddleware
implements
HTTPMiddleware
{
- // members
- private static array $persist_ids = ;
- private static bool $persist_cookie = true;
- private static integer $persist_cookie_expiry = 90;
- private static $persist_cookie_path = NULL;
- private static $persist_cookie_domain = NULL;
- private static bool $persist_cookie_http_only = true;
- protected bool $cookiesPersisted = false;
- // methods
- public void process()
- protected string getLocale()
- protected null|string getPersistLocale()
- protected $this setPersistLocale()
- protected string getPersistKey()
- protected mixed getParamLocale()
- protected string getDomainLocale()
- protected string getDetectedLocale()
- protected string getDefaultLocale()
- protected void validateAllowedLocale()
Hierarchy
Uses
- SilverStripe\Core\Config\Configurable
Implements
- SilverStripe\Control\Middleware\HTTPMiddleware
Tasks
Line | Task |
---|---|
198+ | implement this. |
Members
private
- $persist_ids
—
array
IDs to persist the locale in cookies / session in the front end, CMS, etc
protected
Methods
protected
- getDefaultLocale() — Get default locale
- getDetectedLocale() — Use the configured LocaleDetector to guess the locale
- getDomainLocale() — Get locale from the domain, if the current domain has exactly one locale
- getLocale() — Get the current locale from routing parameters, persistence, browser locale, etc
- getParamLocale() — Get locale from the query_param
- getPersistKey() — Get the Fluent locale persistence key. See the "persist_ids" config static.
- getPersistLocale() — Gets the locale currently set within either the session or cookie.
- setPersistLocale() — Specify the locale to persist between sessions, or to use for the locale outside of locale-routed pages (such as in unit tests, custom controllers, etc).
- validateAllowedLocale() — Check if the current user is allowed to access the curernt locale
public
- process() — Sets the current locale to the FluentState, provided no previous middleware has set it first