class LanguageNegotiator implements LanguageNegotiatorInterface (View source)

Class responsible for performing language negotiation.

Properties

protected PluginManagerInterface $negotiatorManager

The language negotiation method plugin manager.

protected ConfigurableLanguageManagerInterface $languageManager

The language manager.

protected ConfigFactoryInterface $configFactory

The configuration factory.

protected Settings $settings

The settings instance.

protected RequestStack $requestStack

The request stack object.

protected AccountInterface $currentUser

The current active user.

protected array $methods

Local cache for language negotiation method instances.

protected LanguageInterface[] $negotiatedLanguages

An array of language objects keyed by method id.

Methods

__construct(ConfigurableLanguageManagerInterface $language_manager, PluginManagerInterface $negotiator_manager, ConfigFactoryInterface $config_factory, Settings $settings, RequestStack $requestStack)

Constructs a new LanguageNegotiator object.

initLanguageManager()

Initializes the injected language manager with the negotiator.

reset()

Resets the negotiated languages and the method instances.

setCurrentUser(AccountInterface $current_user)

Sets the current active user and resets all language types.

initializeType(string $type)

Initializes the specified language type.

array
getEnabledNegotiators(string $type)

Gets enabled detection methods for the provided language type.

negotiateLanguage(string $type, string $method_id)

Performs language negotiation using the specified negotiation method.

array[]
getNegotiationMethods(string $type = NULL)

Returns the language negotiation methods enabled for a language type.

getNegotiationMethodInstance(string $method_id)

Returns an instance of the specified language negotiation method.

string
getPrimaryNegotiationMethod(string $type)

Returns the ID of the language type's primary language negotiation method.

bool
isNegotiationMethodEnabled(string $method_id, string $type = NULL)

Checks whether a language negotiation method is enabled for a language type.

saveConfiguration(string $type, int[] $enabled_methods)

Saves a list of language negotiation methods for a language type.

purgeConfiguration()

Resave the configuration to purge missing negotiation methods.

updateConfiguration(array $types)

Updates the configuration based on the given language types.

Details

__construct(ConfigurableLanguageManagerInterface $language_manager, PluginManagerInterface $negotiator_manager, ConfigFactoryInterface $config_factory, Settings $settings, RequestStack $requestStack)

Constructs a new LanguageNegotiator object.

Parameters

ConfigurableLanguageManagerInterface $language_manager

The language manager.

PluginManagerInterface $negotiator_manager

The language negotiation methods plugin manager

ConfigFactoryInterface $config_factory

The configuration factory.

Settings $settings

The settings instance.

RequestStack $requestStack

initLanguageManager()

Initializes the injected language manager with the negotiator.

This should be called right after instantiating the negotiator to make it available to the language manager without introducing a circular dependency.

reset()

Resets the negotiated languages and the method instances.

setCurrentUser(AccountInterface $current_user)

Sets the current active user and resets all language types.

Parameters

AccountInterface $current_user

The current active user.

LanguageInterface[] initializeType(string $type)

Initializes the specified language type.

Parameters

string $type

The language type to be initialized.

Return Value

LanguageInterface[]

Returns an array containing a single language keyed by the language negotiation method ID used to determine the language of the specified type. If negotiation is not possible the default language is returned.

protected array getEnabledNegotiators(string $type)

Gets enabled detection methods for the provided language type.

Parameters

string $type

The language type.

Return Value

array

An array of enabled detection methods for the provided language type.

protected LanguageInterface|null negotiateLanguage(string $type, string $method_id)

Performs language negotiation using the specified negotiation method.

Parameters

string $type

The language type to be initialized.

string $method_id

The string identifier of the language negotiation method to use to detect language.

Return Value

LanguageInterface|null

Negotiated language object for given type and method, FALSE otherwise.

array[] getNegotiationMethods(string $type = NULL)

Returns the language negotiation methods enabled for a language type.

Parameters

string $type

(optional) The language type. If no type is specified all the method definitions are returned.

Return Value

array[]

An array of language negotiation method definitions keyed by method id.

LanguageNegotiationMethodInterface getNegotiationMethodInstance(string $method_id)

Returns an instance of the specified language negotiation method.

Parameters

string $method_id

The method identifier.

Return Value

LanguageNegotiationMethodInterface

string getPrimaryNegotiationMethod(string $type)

Returns the ID of the language type's primary language negotiation method.

Parameters

string $type

The language type.

Return Value

string

The identifier of the primary language negotiation method for the given language type, or the default method if none exists.

bool isNegotiationMethodEnabled(string $method_id, string $type = NULL)

Checks whether a language negotiation method is enabled for a language type.

Parameters

string $method_id

The language negotiation method ID.

string $type

(optional) The language type. If none is passed, all the configurable language types will be inspected.

Return Value

bool

TRUE if the method is enabled for at least one of the given language types, or FALSE otherwise.

saveConfiguration(string $type, int[] $enabled_methods)

Saves a list of language negotiation methods for a language type.

Parameters

string $type

The language type.

int[] $enabled_methods

An array of language negotiation method weights keyed by method ID.

purgeConfiguration()

Resave the configuration to purge missing negotiation methods.

updateConfiguration(array $types)

Updates the configuration based on the given language types.

Stores the list of the language types along with information about their configurable state. Stores the default settings if the language type is not configurable.

Parameters

array $types

An array of configurable language types.