Move language element submit to process

Created on 12 June 2013, over 11 years ago
Updated 6 December 2023, about 1 year ago

Follow-up from #111715-194: Convert node/content types into configuration

Problem/Motivation

Currently all core entities have own implementation for language element value.
That means that following hunk is copy/pasted all over

+++ b/core/modules/menu/lib/Drupal/menu/MenuFormController.phpundefined
@@ -76,10 +100,32 @@ protected function actions(array $form, array &$form_state) {
+    // Add the language configuration submit handler. This is needed because the
+    // submit button has custom submit handlers.
+    if (\Drupal::moduleHandler()->moduleExists('language')) {
+      array_unshift($actions['submit']['#submit'],'language_configuration_element_submit');
+      array_unshift($actions['submit']['#submit'], array($this, 'languageConfigurationSubmit'));
+    }
+    // We cannot leverage the regular submit handler definition because we have
+    // button-specific ones here. Hence we need to explicitly set it for the
+    // submit action, otherwise it would be ignored.
+    if (\Drupal::moduleHandler()->moduleExists('translation_entity')) {
+      array_unshift($actions['submit']['#submit'], 'translation_entity_language_configuration_element_submit');
...
+   * Submit handler to update the bundle for the default language configuration.
+   */
+  public function languageConfigurationSubmit(array &$form, array &$form_state) {
+    // Since the machine name is not known yet, and it can be changed anytime,
+    // we have to also update the bundle property for the default language
+    // configuration in order to have the correct bundle value.
+    $form_state['language']['default_language']['bundle'] = $form_state['values']['id'];
+  }

Proposed resolution

As solution we can move this hack to one place to process element and allow core entities to provide alterable language settings

+++ b/core/modules/language/language.moduleundefined
@@ -320,6 +322,18 @@ function language_configuration_element_process($element, &$form_state, &$form)
+  // Do not add the submit callback for the language content settings page,
+  // which is handled separately.
+  if (array_search('language_content_settings_form_submit', $form['#submit']) === FALSE) {
+    // Determine where to attach the language_configuration element submit handler.
+    // @todo Form API: Allow form widgets/sections to declare #submit handlers.
+    if (isset($form['actions']['submit']['#submit']) && array_search('language_configuration_element_submit', $form['actions']['submit']['#submit']) === FALSE) {
+      $form['actions']['submit']['#submit'][] = 'language_configuration_element_submit';
+    }
+    elseif (array_search('language_configuration_element_submit', $form['#submit']) === FALSE) {
+      $form['#submit'][] = 'language_configuration_element_submit';
+    }

Related Issues

#111715-194: Convert node/content types into configuration
#1945226-102: Add language selector on menus

📌 Task
Status

Closed: outdated

Version

9.5

Component
Language system 

Last updated 1 day ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

🇫🇷France andypost

Live updates comments and jobs are added and updated live.
  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024