5 * Hooks provided by the Language module.
14 * Define language types.
17 * An associative array of language type definitions. The keys are the
18 * identifiers, which are also used as names for global variables representing
19 * the types in the bootstrap phase. The values are associative arrays that
20 * may contain the following elements:
21 * - name: The human-readable language type identifier.
22 * - description: A description of the language type.
23 * - locked: A boolean indicating if the user can choose whether to configure
24 * the language type or not using the UI.
25 * - fixed: A fixed array of language negotiation method identifiers to use to
26 * initialize this language. If locked is set to TRUE and fixed is set, it
27 * will always use the specified methods in the given priority order. If not
28 * present and locked is TRUE then language-interface will be
31 * @todo Rename the 'fixed' key to something more meaningful, for instance
32 * 'negotiation settings'. See https://www.drupal.org/node/2166879.
34 * @see hook_language_types_info_alter()
35 * @ingroup language_negotiation
37 function hook_language_types_info() {
39 'custom_language_type' => [
40 'name' => t('Custom language'),
41 'description' => t('A custom language type.'),
44 'fixed_custom_language_type' => [
46 'fixed' => ['custom_language_negotiation_method'],
52 * Perform alterations on language types.
54 * @param array $language_types
55 * Array of language type definitions.
57 * @see hook_language_types_info()
58 * @ingroup language_negotiation
60 function hook_language_types_info_alter(array &$language_types) {
61 if (isset($language_types['custom_language_type'])) {
62 $language_types['custom_language_type_custom']['description'] = t('A far better description.');
67 * Perform alterations on language negotiation methods.
69 * @param array $negotiation_info
70 * Array of language negotiation method definitions.
72 * @ingroup language_negotiation
74 function hook_language_negotiation_info_alter(array &$negotiation_info) {
75 if (isset($negotiation_info['custom_language_method'])) {
76 $negotiation_info['custom_language_method']['config'] = 'admin/config/regional/language/detection/custom-language-method';
81 * Allow modules to alter the language fallback candidates.
83 * @param array $candidates
84 * An array of language codes whose order will determine the language fallback
86 * @param array $context
87 * A language fallback context.
89 * @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates()
91 function hook_language_fallback_candidates_alter(array &$candidates, array $context) {
92 $candidates = array_reverse($candidates);
96 * Allow modules to alter the fallback candidates for specific operations.
98 * @param array $candidates
99 * An array of language codes whose order will determine the language fallback
101 * @param array $context
102 * A language fallback context.
104 * @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates()
106 function hook_language_fallback_candidates_OPERATION_alter(array &$candidates, array $context) {
107 // We know that the current OPERATION deals with entities so no need to check
109 if ($context['data']->getEntityTypeId() == 'node') {
110 $candidates = array_reverse($candidates);
115 * @} End of "addtogroup hooks".