language.module

Same filename and directory in other branches
  1. 10 core/modules/language/language.module
  2. 11.x core/modules/language/language.module
  3. 9 core/modules/language/language.module
  4. 8.9.x core/modules/language/language.module

File

core/modules/language/language.module

View source
<?php


/**
 * @file
 */

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Element\LanguageConfiguration;
use Drupal\language\Entity\ContentLanguageSettings;

/**
 * Submit handler for the forms that have a language_configuration element.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use
 *   \Drupal\language\Element\LanguageConfiguration::submit() instead.
 *
 * @see https://www.drupal.org/node/3566774
 */
function language_configuration_element_submit(&$form, FormStateInterface $form_state) : void {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. Use \\Drupal\\language\\Element\\LanguageConfiguration::submit() instead. See https://www.drupal.org/node/3566774', E_USER_DEPRECATED);
  LanguageConfiguration::submit($form, $form_state);
}

/**
 * Returns the default language code assigned to an entity type and a bundle.
 *
 * @param string $entity_type
 *   The entity type.
 * @param string $bundle
 *   The bundle name.
 *
 * @return string
 *   The language code.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no
 *   replacement.
 *
 * @see https://www.drupal.org/node/3566774
 */
function language_get_default_langcode($entity_type, $bundle) {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no replacement. See https://www.drupal.org/node/3566774', E_USER_DEPRECATED);
  $configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity_type, $bundle);
  $default_value = NULL;
  $language_interface = \Drupal::languageManager()->getCurrentLanguage();
  switch ($configuration->getDefaultLangcode()) {
    case LanguageInterface::LANGCODE_SITE_DEFAULT:
      $default_value = \Drupal::languageManager()->getDefaultLanguage()
        ->getId();
      break;

    case 'current_interface':
      $default_value = $language_interface->getId();
      break;

    case 'authors_default':
      $user = \Drupal::currentUser();
      $language_code = $user->getPreferredLangcode();
      if (!empty($language_code)) {
        $default_value = $language_code;
      }
      else {
        $default_value = $language_interface->getId();
      }
      break;

  }
  if ($default_value) {
    return $default_value;
  }
  // If we still do not have a default value, just return the value stored in
  // the configuration; it has to be an actual language code.
  return $configuration->getDefaultLangcode();
}

/**
 * Update the list of prefixes from the installed languages.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no
 *   replacement.
 *
 * @see https://www.drupal.org/node/3566774
 */
function language_negotiation_url_prefixes_update() : void {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no replacement. See https://www.drupal.org/node/3566774', E_USER_DEPRECATED);
  $config = \Drupal::configFactory()->getEditable('language.negotiation');
  $prefixes = $config->get('url.prefixes');
  foreach (\Drupal::languageManager()->getLanguages() as $language) {
    // The prefix for this language should be updated if it's not assigned yet
    // or the prefix is set to the empty string.
    if (empty($prefixes[$language->getId()])) {
      // For the default language, set the prefix to the empty string,
      // otherwise use the langcode.
      $prefixes[$language->getId()] = $language->isDefault() ? '' : $language->getId();
    }
    // Otherwise we keep the configured prefix.
  }
  $config->set('url.prefixes', $prefixes)
    ->save();
}

/**
 * Returns language mappings between browser and Drupal language codes.
 *
 * @return array
 *   An array containing browser language codes as keys with corresponding
 *   Drupal language codes as values.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no
 *   replacement.
 *
 * @see https://www.drupal.org/node/3566774
 */
function language_get_browser_drupal_langcode_mappings() {
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:13.0.0. There is no replacement. See https://www.drupal.org/node/3566774', E_USER_DEPRECATED);
  $config = \Drupal::config('language.mappings');
  if ($config->isNew()) {
    return [];
  }
  return $config->get('map');
}

Functions

Title Deprecated Summary
language_configuration_element_submit

in drupal:11.4.0 and is removed from drupal:13.0.0. Use \Drupal\language\Element\LanguageConfiguration::submit() instead.

Submit handler for the forms that have a language_configuration element.
language_get_browser_drupal_langcode_mappings

in drupal:11.4.0 and is removed from drupal:13.0.0. There is no replacement.

Returns language mappings between browser and Drupal language codes.
language_get_default_langcode

in drupal:11.4.0 and is removed from drupal:13.0.0. There is no replacement.

Returns the default language code assigned to an entity type and a bundle.
language_negotiation_url_prefixes_update

in drupal:11.4.0 and is removed from drupal:13.0.0. There is no replacement.

Update the list of prefixes from the installed languages.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.