Drupal 8  8.0.2
LanguageNegotiator Class Reference
Inheritance diagram for LanguageNegotiator:

Public Member Functions

 __construct (ConfigurableLanguageManagerInterface $language_manager, PluginManagerInterface $negotiator_manager, ConfigFactoryInterface $config_factory, Settings $settings, RequestStack $requestStack)
 
 initLanguageManager ()
 
 reset ()
 
 setCurrentUser (AccountInterface $current_user)
 
 initializeType ($type)
 
 getNegotiationMethods ($type=NULL)
 
 getNegotiationMethodInstance ($method_id)
 
 getPrimaryNegotiationMethod ($type)
 
 isNegotiationMethodEnabled ($method_id, $type=NULL)
 
 saveConfiguration ($type, $enabled_methods)
 
 purgeConfiguration ()
 
 updateConfiguration (array $types)
 

Protected Member Functions

 getEnabledNegotiators ($type)
 
 negotiateLanguage ($type, $method_id)
 

Protected Attributes

 $negotiatorManager
 
 $languageManager
 
 $configFactory
 
 $settings
 
 $requestStack
 
 $currentUser
 
 $methods
 
 $negotiatedLanguages = array()
 

Additional Inherited Members

- Data Fields inherited from LanguageNegotiatorInterface
const METHOD_ID = 'language-default'
 

Detailed Description

Class responsible for performing language negotiation.

Constructor & Destructor Documentation

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

Constructs a new LanguageNegotiator object.

Parameters
\Drupal\language\ConfigurableLanguageManagerInterface$language_managerThe language manager.
\Drupal\Component\Plugin\PluginManagerInterface$negotiator_managerThe language negotiation methods plugin manager
\Drupal\Core\Config\ConfigFactoryInterface$config_factoryThe configuration factory.
\Drupal\Core\Site\Settings$settingsThe settings instance.

References LanguageNegotiator\$settings, Drupal\configFactory(), Drupal\languageManager(), and Drupal\requestStack().

Here is the call graph for this function:

Member Function Documentation

getEnabledNegotiators (   $type)
protected

Gets enabled detection methods for the provided language type.

Parameters
string$typeThe language type.
Returns
array An array of enabled detection methods for the provided language type.

References Drupal\configFactory().

Referenced by LanguageNegotiator\getNegotiationMethods(), LanguageNegotiator\getPrimaryNegotiationMethod(), LanguageNegotiator\initializeType(), LanguageNegotiator\isNegotiationMethodEnabled(), and LanguageNegotiator\purgeConfiguration().

Here is the call graph for this function:

Here is the caller graph for this function:

getNegotiationMethodInstance (   $method_id)

{Returns an instance of the specified language negotiation method.

Parameters
string$method_idThe method identifier.
Returns
}

Implements LanguageNegotiatorInterface.

References Drupal\configFactory(), Drupal\currentUser(), and Drupal\languageManager().

Referenced by LanguageNegotiator\initializeType(), and LanguageNegotiator\negotiateLanguage().

Here is the call graph for this function:

Here is the caller graph for this function:

getNegotiationMethods (   $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.
Returns
array[] An array of language negotiation method definitions keyed by method id.
}

Implements LanguageNegotiatorInterface.

References LanguageNegotiator\getEnabledNegotiators().

Referenced by LanguageNegotiator\saveConfiguration(), and LanguageNegotiator\updateConfiguration().

Here is the call graph for this function:

Here is the caller graph for this function:

getPrimaryNegotiationMethod (   $type)

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

Parameters
$typeThe language type.
Returns
string The identifier of the primary language negotiation method for the given language type, or the default method if none exists.
}

Implements LanguageNegotiatorInterface.

References LanguageNegotiator\getEnabledNegotiators(), and LanguageNegotiatorInterface\METHOD_ID.

Here is the call graph for this function:

initializeType (   $type)

{Initializes the specified language type.

Parameters
string$typeThe language type to be initialized.
Returns
[] 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.
}

Implements LanguageNegotiatorInterface.

References Drupal\currentUser(), LanguageNegotiator\getEnabledNegotiators(), LanguageNegotiator\getNegotiationMethodInstance(), Drupal\languageManager(), and LanguageNegotiator\negotiateLanguage().

Here is the call graph for this function:

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.

References Drupal\languageManager().

Here is the call graph for this function:

isNegotiationMethodEnabled (   $method_id,
  $type = NULL 
)

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

Parameters
$method_idThe language negotiation method ID.
$type(optional) The language type. If none is passed, all the configurable language types will be inspected.
Returns
bool TRUE if the method is enabled for at least one of the given language types, or FALSE otherwise.
}

Implements LanguageNegotiatorInterface.

References LanguageNegotiator\getEnabledNegotiators(), and Drupal\languageManager().

Here is the call graph for this function:

negotiateLanguage (   $type,
  $method_id 
)
protected

Performs language negotiation using the specified negotiation method.

Parameters
string$typeThe language type to be initialized.
string$method_idThe string identifier of the language negotiation method to use to detect language.
Returns
|null Negotiated language object for given type and method, FALSE otherwise.

References LanguageNegotiator\getNegotiationMethodInstance(), Drupal\languageManager(), and Drupal\requestStack().

Referenced by LanguageNegotiator\initializeType().

Here is the call graph for this function:

Here is the caller graph for this function:

purgeConfiguration ( )

{Resave the configuration to purge missing negotiation methods.}

Implements LanguageNegotiatorInterface.

References LanguageNegotiator\getEnabledNegotiators(), Drupal\languageManager(), and LanguageNegotiator\saveConfiguration().

Here is the call graph for this function:

reset ( )

{Resets the negotiated languages and the method instances.}

Implements LanguageNegotiatorInterface.

Referenced by LanguageNegotiator\setCurrentUser().

Here is the caller graph for this function:

saveConfiguration (   $type,
  $enabled_methods 
)

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

Parameters
string$typeThe language type.
int[]$enabled_methods An array of language negotiation method weights keyed by method ID.
}

Implements LanguageNegotiatorInterface.

References Drupal\configFactory(), LanguageNegotiator\getNegotiationMethods(), and Drupal\languageManager().

Referenced by LanguageNegotiator\purgeConfiguration(), and LanguageNegotiator\updateConfiguration().

Here is the call graph for this function:

Here is the caller graph for this function:

setCurrentUser ( AccountInterface  $current_user)

{Sets the current active user and resets all language types.

Parameters
\Drupal\Core\Session\AccountInterface$current_userThe current active user.
}

Implements LanguageNegotiatorInterface.

References Drupal\currentUser(), and LanguageNegotiator\reset().

Here is the call graph for this function:

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
string[]$types An array of configurable language types.
}

Implements LanguageNegotiatorInterface.

References LanguageNegotiator\getNegotiationMethods(), Drupal\languageManager(), LanguageNegotiationUI\METHOD_ID, and LanguageNegotiator\saveConfiguration().

Here is the call graph for this function:

Field Documentation

$currentUser
protected

The current active user.

Returns
$settings
protected

The settings instance.

Returns

Referenced by LanguageNegotiator\__construct().


The documentation for this class was generated from the following file: