class LanguageNegotiationUrlFallback extends LanguageNegotiationMethodBase (View source)

Class that determines the language to be assigned to URLs when none is detected.

The language negotiation process has a fallback chain that ends with the default language negotiation method. Each built-in language type has a separate initialization:

  • Interface language, which is the only configurable one, always gets a valid value. If no request-specific language is detected, the default language will be used.
  • Content language merely inherits the interface language by default.
  • URL language is detected from the requested URL and will be used to rewrite URLs appearing in the page being rendered. If no language can be detected, there are two possibilities:
    • If the default language has no configured path prefix or domain, then the default language is used. This guarantees that (missing) URL prefixes are preserved when navigating through the site.
    • If the default language has a configured path prefix or domain, a requested URL having an empty prefix or domain is an anomaly that must be fixed. This is done by introducing a prefix or domain in the rendered page matching the detected interface language.

Constants

METHOD_ID

The language negotiation method id.

Properties

protected LanguageManagerInterface $languageManager

The language manager.

from  LanguageNegotiationMethodBase
protected ConfigFactoryInterface $config

The configuration factory.

from  LanguageNegotiationMethodBase
protected AccountInterface $currentUser

The current active user.

from  LanguageNegotiationMethodBase

Methods

setLanguageManager(ConfigurableLanguageManagerInterface $language_manager)

Injects the language manager.

setConfig(ConfigFactoryInterface $config)

Injects the configuration factory.

setCurrentUser(AccountInterface $current_user)

Injects the current user.

persist(LanguageInterface $language)

Notifies the plugin that the language code it returned has been accepted.

string
getLangcode(Request $request = NULL)

Performs language negotiation.

Details

setLanguageManager(ConfigurableLanguageManagerInterface $language_manager)

Injects the language manager.

Parameters

ConfigurableLanguageManagerInterface $language_manager

The language manager to be used to retrieve the language list and the already negotiated languages.

setConfig(ConfigFactoryInterface $config)

Injects the configuration factory.

Parameters

ConfigFactoryInterface $config

The configuration factory.

setCurrentUser(AccountInterface $current_user)

Injects the current user.

Parameters

AccountInterface $current_user

The current active user.

persist(LanguageInterface $language)

Notifies the plugin that the language code it returned has been accepted.

Parameters

LanguageInterface $language

The accepted language.

string getLangcode(Request $request = NULL)

Performs language negotiation.

Parameters

Request $request

(optional) The current request. Defaults to NULL if it has not been initialized yet.

Return Value

string

A valid language code or FALSE if the negotiation was unsuccessful.