Skip to content
Snippets Groups Projects
Select Git revision
  • 2f370af9c5dbfd7b52639d3bd42818c21066824e
  • 11.x default protected
  • 10.6.x protected
  • 11.2.x protected
  • 10.5.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.3 protected
  • 11.2.4 protected
  • 10.5.2 protected
  • 11.2.3 protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
41 results

language.api.php

Blame
  • xjm's avatar
    Issue #2491155 by mikeburrelljr, Mac_Weber, opdavies: Update drupal.org and...
    Jess authored
    Issue #2491155 by mikeburrelljr, Mac_Weber, opdavies: Update drupal.org and kernel.org URLs in core modules (Follow-up to 2489912)
    088f8b35
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    language.api.php 3.51 KiB
    <?php
    
    /**
     * @file
     * Hooks provided by the Language module.
     */
    
    /**
     * @addtogroup hooks
     * @{
     */
    
    /**
     * Define language types.
     *
     * @return
     *   An associative array of language type definitions. The keys are the
     *   identifiers, which are also used as names for global variables representing
     *   the types in the bootstrap phase. The values are associative arrays that
     *   may contain the following elements:
     *   - name: The human-readable language type identifier.
     *   - description: A description of the language type.
     *   - locked: A boolean indicating if the user can choose whether to configure
     *     the language type or not using the UI.
     *   - fixed: A fixed array of language negotiation method identifiers to use to
     *     initialize this language. If locked is set to TRUE and fixed is set, it
     *     will always use the specified methods in the given priority order. If not
     *     present and locked is TRUE then language-interface will be
     *     used.
     *
     *  @todo Rename the 'fixed' key to something more meaningful, for instance
     *     'negotiation settings'. See https://www.drupal.org/node/2166879.
     *
     * @see hook_language_types_info_alter()
     * @ingroup language_negotiation
     */
    function hook_language_types_info() {
      return array(
        'custom_language_type' => array(
          'name' => t('Custom language'),
          'description' => t('A custom language type.'),
          'locked' => FALSE,
        ),
        'fixed_custom_language_type' => array(
          'locked' => TRUE,
          'fixed' => array('custom_language_negotiation_method'),
        ),
      );
    }
    
    /**
     * Perform alterations on language types.
     *
     * @param $language_types
     *   Array of language type definitions.
     *
     * @see hook_language_types_info()
     * @ingroup language_negotiation
     */
    function hook_language_types_info_alter(array &$language_types) {
      if (isset($language_types['custom_language_type'])) {
        $language_types['custom_language_type_custom']['description'] = t('A far better description.');
      }
    }
    
    /**
     * Perform alterations on language negotiation methods.
     *
     * @param $negotiation_info
     *   Array of language negotiation method definitions.
     *
     * @ingroup language_negotiation
     */
    function hook_language_negotiation_info_alter(array &$negotiation_info) {
      if (isset($negotiation_info['custom_language_method'])) {
        $negotiation_info['custom_language_method']['config'] = 'admin/config/regional/language/detection/custom-language-method';
      }
    }
    
    /**
     * Allow modules to alter the language fallback candidates.
     *
     * @param array $candidates
     *   An array of language codes whose order will determine the language fallback
     *   order.
     * @param array $context
     *   A language fallback context.
     *
     * @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates()
     */
    function hook_language_fallback_candidates_alter(array &$candidates, array $context) {
      $candidates = array_reverse($candidates);
    }
    
    /**
     * Allow modules to alter the fallback candidates for specific operations.
     *
     * @param array $candidates
     *   An array of language codes whose order will determine the language fallback
     *   order.
     * @param array $context
     *   A language fallback context.
     *
     * @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates()
     */
    function hook_language_fallback_candidates_OPERATION_alter(array &$candidates, array $context) {
      // We know that the current OPERATION deals with entities so no need to check
      // here.
      if ($context['data']->getEntityTypeId() == 'node') {
        $candidates = array_reverse($candidates);
      }
    }
    
    /**
     * @} End of "addtogroup hooks".
     */