Mercurial > hg > isophonics-drupal-site
comparison core/modules/language/language.api.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * Hooks provided by the Language module. | |
6 */ | |
7 | |
8 /** | |
9 * @addtogroup hooks | |
10 * @{ | |
11 */ | |
12 | |
13 /** | |
14 * Define language types. | |
15 * | |
16 * @return array | |
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 | |
29 * used. | |
30 * | |
31 * @todo Rename the 'fixed' key to something more meaningful, for instance | |
32 * 'negotiation settings'. See https://www.drupal.org/node/2166879. | |
33 * | |
34 * @see hook_language_types_info_alter() | |
35 * @ingroup language_negotiation | |
36 */ | |
37 function hook_language_types_info() { | |
38 return [ | |
39 'custom_language_type' => [ | |
40 'name' => t('Custom language'), | |
41 'description' => t('A custom language type.'), | |
42 'locked' => FALSE, | |
43 ], | |
44 'fixed_custom_language_type' => [ | |
45 'locked' => TRUE, | |
46 'fixed' => ['custom_language_negotiation_method'], | |
47 ], | |
48 ]; | |
49 } | |
50 | |
51 /** | |
52 * Perform alterations on language types. | |
53 * | |
54 * @param array $language_types | |
55 * Array of language type definitions. | |
56 * | |
57 * @see hook_language_types_info() | |
58 * @ingroup language_negotiation | |
59 */ | |
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.'); | |
63 } | |
64 } | |
65 | |
66 /** | |
67 * Perform alterations on language negotiation methods. | |
68 * | |
69 * @param array $negotiation_info | |
70 * Array of language negotiation method definitions. | |
71 * | |
72 * @ingroup language_negotiation | |
73 */ | |
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'; | |
77 } | |
78 } | |
79 | |
80 /** | |
81 * Allow modules to alter the language fallback candidates. | |
82 * | |
83 * @param array $candidates | |
84 * An array of language codes whose order will determine the language fallback | |
85 * order. | |
86 * @param array $context | |
87 * A language fallback context. | |
88 * | |
89 * @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates() | |
90 */ | |
91 function hook_language_fallback_candidates_alter(array &$candidates, array $context) { | |
92 $candidates = array_reverse($candidates); | |
93 } | |
94 | |
95 /** | |
96 * Allow modules to alter the fallback candidates for specific operations. | |
97 * | |
98 * @param array $candidates | |
99 * An array of language codes whose order will determine the language fallback | |
100 * order. | |
101 * @param array $context | |
102 * A language fallback context. | |
103 * | |
104 * @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates() | |
105 */ | |
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 | |
108 // here. | |
109 if ($context['data']->getEntityTypeId() == 'node') { | |
110 $candidates = array_reverse($candidates); | |
111 } | |
112 } | |
113 | |
114 /** | |
115 * @} End of "addtogroup hooks". | |
116 */ |