Unverified Commit a0dcfd36 authored by Alex Pott's avatar Alex Pott
Browse files

task: #3574727 Deprecate remaining language.module code

By: nicxvan
By: claudiu.cristea
By: berdir
By: penyaskito
parent a2b01208
Loading
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -16423,12 +16423,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/language/tests/language_elements_test/src/Form/LanguageConfigurationElement.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\language_elements_test\\\\Form\\\\LanguageConfigurationElementTest\\:\\:submitForm\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/language/tests/language_elements_test/src/Form/LanguageConfigurationElementTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\language_test\\\\Controller\\\\LanguageTestController\\:\\:create\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+2 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\language\Element\LanguageConfiguration;
use Drupal\language\Entity\ContentLanguageSettings;

/**
@@ -80,7 +81,7 @@ public function form(array $form, FormStateInterface $form_state) {
        '#default_value' => $language_configuration,
      ];

      $form['#submit'][] = 'language_configuration_element_submit';
      $form['#submit'][] = LanguageConfiguration::class . '::submit';
    }

    $form['actions'] = ['#type' => 'actions'];
+13 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@

use Drupal\Core\Cache\BackendChain;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

@@ -19,16 +20,27 @@ class LanguageMapper {
   */
  protected BackendChain $cache;

  /**
   * The config factory service.
   */
  protected ConfigFactoryInterface $configFactory;

  public function __construct(
    #[Autowire('@cache.discovery')]
    CacheBackendInterface $persistent_cache,
    #[Autowire('@cache.memory')]
    CacheBackendInterface $memory_cache,
    protected ModuleHandlerInterface $moduleHandler,
    ?ConfigFactoryInterface $config_factory = NULL,
  ) {
    $this->cache = new BackendChain();
    $this->cache->appendBackend($memory_cache);
    $this->cache->appendBackend($persistent_cache);
    if (!$config_factory) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $config_factory argument is deprecated in drupal:11.4.0 and it will be required in drupal:12.0.0. See https://www.drupal.org/node/3566774', E_USER_DEPRECATED);
      $config_factory = \Drupal::configFactory();
    }
    $this->configFactory = $config_factory;
  }

  /**
@@ -63,7 +75,7 @@ public function getMappings(): array {
    // Get language mapping if available to map to Drupal language codes.
    // This is configurable in the user interface and not expensive to get, so
    // we don't include it in the cached language list.
    $language_mappings = $this->moduleHandler->moduleExists('language') ? language_get_browser_drupal_langcode_mappings() : [];
    $language_mappings = $this->moduleHandler->moduleExists('language') ? $this->configFactory->get('language.mappings')->get('map') : [];
    foreach ($langcodes as $langcode) {
      // If this language code is available in a Drupal mapping, use that to
      // compute a possibility for matching from the Drupal langcode to the
+2 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\language\Element\LanguageConfiguration;
use Drupal\language\Entity\ContentLanguageSettings;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -150,7 +151,7 @@ public function form(array $form, FormStateInterface $form_state) {
        '#default_value' => $language_configuration,
      ];

      $form['#submit'][] = 'language_configuration_element_submit';
      $form['#submit'][] = LanguageConfiguration::class . '::submit';
    }

    $form['actions'] = ['#type' => 'actions'];
+34 −36
Original line number Diff line number Diff line
@@ -4,10 +4,11 @@
 * @file
 */

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

/**
 * Processes a language select list form element.
@@ -17,49 +18,28 @@
 *
 * @return array
 *   The processed form element.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. Use
 *   \Drupal\language\Hook\LanguageHooks::processLanguageSelect() instead.
 *
 * @see https://www.drupal.org/node/3566774
 */
function language_process_language_select($element) {
  // Don't set the options if another module (translation for example) already
  // set the options.
  if (!isset($element['#options'])) {
    $element['#options'] = [];
    foreach (\Drupal::languageManager()->getLanguages($element['#languages']) as $langcode => $language) {
      $element['#options'][$langcode] = $language->isLocked() ? t('- @name -', ['@name' => $language->getName()]) : $language->getName();
    }
  }
  return $element;
  @trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.4.0 and is removed from drupal:12.0.0. Use \Drupal\language\Hook\LanguageHooks::processLanguageSelect() instead. See https://www.drupal.org/node/3566774', E_USER_DEPRECATED);
  return \Drupal::service(LanguageHooks::class)->processLanguageSelect($element);
}

/**
 * Submit handler for the forms that have a language_configuration element.
 *
 * @deprecated in drupal:11.4.0 and is removed from drupal:12.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 {
  // Iterate through all the language_configuration elements and save their
  // values.
  // In case we are editing a bundle, we must check the new bundle name,
  // because e.g. hook_ENTITY_update fired before.
  if ($language = $form_state->get('language')) {
    foreach ($language as $element_name => $values) {
      $entity_type_id = $values['entity_type'];
      $bundle = $values['bundle'];
      $form_object = $form_state->getFormObject();
      if ($form_object instanceof EntityFormInterface) {
        /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
        $entity = $form_object->getEntity();
        if ($entity->getEntityType()->getBundleOf()) {
          $bundle = $entity->id();
          $language[$element_name]['bundle'] = $bundle;
        }
      }
      $config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle);
      $config->setDefaultLangcode($form_state->getValue([$element_name, 'langcode']));
      $config->setLanguageAlterable($form_state->getValue([$element_name, 'language_alterable']));
      $config->save();

      // Set the form_state language with the updated bundle.
      $form_state->set('language', $language);
    }
  }
  @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);
}

/**
@@ -72,8 +52,14 @@ function language_configuration_element_submit(&$form, FormStateInterface $form_
 *
 * @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;
@@ -109,8 +95,14 @@ function language_get_default_langcode($entity_type, $bundle) {

/**
 * 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) {
@@ -132,8 +124,14 @@ function language_negotiation_url_prefixes_update(): void {
 * @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 [];
Loading