public LanguageNegotiator::initializeType($type)
Initializes the specified language type.
Parameters
string $type: The language type to be initialized.
Return value
\Drupal\Core\Language\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.
Overrides LanguageNegotiatorInterface::initializeType
File
- core/modules/language/src/LanguageNegotiator.php, line 123
Class
- LanguageNegotiator
- Class responsible for performing language negotiation.
Namespace
Drupal\language
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public function initializeType( $type ) { $language = NULL; if ( $this ->currentUser) { // Execute the language negotiation methods in the order they were set up // and return the first valid language found. foreach ( $this ->getEnabledNegotiators( $type ) as $method_id => $info ) { if (!isset( $this ->negotiatedLanguages[ $method_id ])) { $this ->negotiatedLanguages[ $method_id ] = $this ->negotiateLanguage( $type , $method_id ); } // Since objects are references, we need to return a clone to prevent // the language negotiation method cache from being unintentionally // altered. The same methods might be used with different language types // based on configuration. $language = ! empty ( $this ->negotiatedLanguages[ $method_id ]) ? clone ( $this ->negotiatedLanguages[ $method_id ]) : NULL; if ( $language ) { $this ->getNegotiationMethodInstance( $method_id )->persist( $language ); break ; } } } if (! $language ) { // If no other language was found use the default one. $language = $this ->languageManager->getDefaultLanguage(); $method_id = static ::METHOD_ID; } return array ( $method_id => $language ); } |
Please login to continue.