annotate core/modules/language/language.api.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Hooks provided by the Language module.
Chris@0 6 */
Chris@0 7
Chris@0 8 /**
Chris@0 9 * @addtogroup hooks
Chris@0 10 * @{
Chris@0 11 */
Chris@0 12
Chris@0 13 /**
Chris@0 14 * Define language types.
Chris@0 15 *
Chris@0 16 * @return array
Chris@0 17 * An associative array of language type definitions. The keys are the
Chris@0 18 * identifiers, which are also used as names for global variables representing
Chris@0 19 * the types in the bootstrap phase. The values are associative arrays that
Chris@0 20 * may contain the following elements:
Chris@0 21 * - name: The human-readable language type identifier.
Chris@0 22 * - description: A description of the language type.
Chris@0 23 * - locked: A boolean indicating if the user can choose whether to configure
Chris@0 24 * the language type or not using the UI.
Chris@0 25 * - fixed: A fixed array of language negotiation method identifiers to use to
Chris@0 26 * initialize this language. If locked is set to TRUE and fixed is set, it
Chris@0 27 * will always use the specified methods in the given priority order. If not
Chris@0 28 * present and locked is TRUE then language-interface will be
Chris@0 29 * used.
Chris@0 30 *
Chris@0 31 * @todo Rename the 'fixed' key to something more meaningful, for instance
Chris@0 32 * 'negotiation settings'. See https://www.drupal.org/node/2166879.
Chris@0 33 *
Chris@0 34 * @see hook_language_types_info_alter()
Chris@0 35 * @ingroup language_negotiation
Chris@0 36 */
Chris@0 37 function hook_language_types_info() {
Chris@0 38 return [
Chris@0 39 'custom_language_type' => [
Chris@0 40 'name' => t('Custom language'),
Chris@0 41 'description' => t('A custom language type.'),
Chris@0 42 'locked' => FALSE,
Chris@0 43 ],
Chris@0 44 'fixed_custom_language_type' => [
Chris@0 45 'locked' => TRUE,
Chris@0 46 'fixed' => ['custom_language_negotiation_method'],
Chris@0 47 ],
Chris@0 48 ];
Chris@0 49 }
Chris@0 50
Chris@0 51 /**
Chris@0 52 * Perform alterations on language types.
Chris@0 53 *
Chris@0 54 * @param array $language_types
Chris@0 55 * Array of language type definitions.
Chris@0 56 *
Chris@0 57 * @see hook_language_types_info()
Chris@0 58 * @ingroup language_negotiation
Chris@0 59 */
Chris@0 60 function hook_language_types_info_alter(array &$language_types) {
Chris@0 61 if (isset($language_types['custom_language_type'])) {
Chris@0 62 $language_types['custom_language_type_custom']['description'] = t('A far better description.');
Chris@0 63 }
Chris@0 64 }
Chris@0 65
Chris@0 66 /**
Chris@0 67 * Perform alterations on language negotiation methods.
Chris@0 68 *
Chris@0 69 * @param array $negotiation_info
Chris@0 70 * Array of language negotiation method definitions.
Chris@0 71 *
Chris@0 72 * @ingroup language_negotiation
Chris@0 73 */
Chris@0 74 function hook_language_negotiation_info_alter(array &$negotiation_info) {
Chris@0 75 if (isset($negotiation_info['custom_language_method'])) {
Chris@0 76 $negotiation_info['custom_language_method']['config'] = 'admin/config/regional/language/detection/custom-language-method';
Chris@0 77 }
Chris@0 78 }
Chris@0 79
Chris@0 80 /**
Chris@0 81 * Allow modules to alter the language fallback candidates.
Chris@0 82 *
Chris@0 83 * @param array $candidates
Chris@0 84 * An array of language codes whose order will determine the language fallback
Chris@0 85 * order.
Chris@0 86 * @param array $context
Chris@0 87 * A language fallback context.
Chris@0 88 *
Chris@0 89 * @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates()
Chris@0 90 */
Chris@0 91 function hook_language_fallback_candidates_alter(array &$candidates, array $context) {
Chris@0 92 $candidates = array_reverse($candidates);
Chris@0 93 }
Chris@0 94
Chris@0 95 /**
Chris@0 96 * Allow modules to alter the fallback candidates for specific operations.
Chris@0 97 *
Chris@0 98 * @param array $candidates
Chris@0 99 * An array of language codes whose order will determine the language fallback
Chris@0 100 * order.
Chris@0 101 * @param array $context
Chris@0 102 * A language fallback context.
Chris@0 103 *
Chris@0 104 * @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates()
Chris@0 105 */
Chris@0 106 function hook_language_fallback_candidates_OPERATION_alter(array &$candidates, array $context) {
Chris@0 107 // We know that the current OPERATION deals with entities so no need to check
Chris@0 108 // here.
Chris@0 109 if ($context['data']->getEntityTypeId() == 'node') {
Chris@0 110 $candidates = array_reverse($candidates);
Chris@0 111 }
Chris@0 112 }
Chris@0 113
Chris@0 114 /**
Chris@0 115 * @} End of "addtogroup hooks".
Chris@0 116 */