public ConfigurableLanguageManager::getFallbackCandidates(array $context = array())
Returns the language fallback candidates for a given context.
Parameters
array $context: (optional) An associative array of data that can be useful to determine the fallback sequence. The following keys are used in core:
- langcode: Language code of the desired language.
-
operation: The name of the operation indicating the context where language fallback is being applied. The following operations are defined in core, but more may be defined in contributed modules:
- entity_view: Invoked when an entity is about to be displayed. The data key contains the loaded entity.
- views_query: Invoked when a field based views query is performed. The data key contains a reference to the field object.
- locale_lookup: Invoked when a string translation was not found. The data key contains the source string.
- data: A data structure that makes sense in the provided context, see above.
Return value
array An array of language codes sorted by priority: first values should be tried first.
Overrides LanguageManager::getFallbackCandidates
File
- core/modules/language/src/ConfigurableLanguageManager.php, line 366
Class
- ConfigurableLanguageManager
- Overrides default LanguageManager to provide configured languages.
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 33 34 35 | public function getFallbackCandidates( array $context = array ()) { if ( $this ->isMultilingual()) { $candidates = array (); if ( empty ( $context [ 'operation' ]) || $context [ 'operation' ] != 'locale_lookup' ) { // If the fallback context is not locale_lookup, initialize the // candidates with languages ordered by weight and add // LanguageInterface::LANGCODE_NOT_SPECIFIED at the end. Interface // translation fallback should only be based on explicit configuration // gathered via the alter hooks below. $candidates = array_keys ( $this ->getLanguages()); $candidates [] = LanguageInterface::LANGCODE_NOT_SPECIFIED; $candidates = array_combine ( $candidates , $candidates ); // The first candidate should always be the desired language if // specified. if (! empty ( $context [ 'langcode' ])) { $candidates = array ( $context [ 'langcode' ] => $context [ 'langcode' ]) + $candidates ; } } // Let other modules hook in and add/change candidates. $type = 'language_fallback_candidates' ; $types = array (); if (! empty ( $context [ 'operation' ])) { $types [] = $type . '_' . $context [ 'operation' ]; } $types [] = $type ; $this ->moduleHandler->alter( $types , $candidates , $context ); } else { $candidates = parent::getFallbackCandidates( $context ); } return $candidates ; } |
Please login to continue.