From 35cfc9ee89e1237637f9f8cb8a973ddf8b053cea Mon Sep 17 00:00:00 2001 From: babruix Date: Tue, 19 Mar 2013 13:09:19 +0100 Subject: [PATCH] Issue #1945226 by Gabor Hojtsy: Added language selector on menus --- .../menu/lib/Drupal/menu/MenuFormController.php | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/core/modules/menu/lib/Drupal/menu/MenuFormController.php b/core/modules/menu/lib/Drupal/menu/MenuFormController.php index ff42a20..e229451 100644 --- a/core/modules/menu/lib/Drupal/menu/MenuFormController.php +++ b/core/modules/menu/lib/Drupal/menu/MenuFormController.php @@ -63,6 +63,31 @@ public function form(array $form, array &$form_state, EntityInterface $menu) { $form['links'] = menu_overview_form($form['links'], $form_state); } + // $form['langcode'] is not wrapped in an if (module_exists('language')) + // check because the language_select form element works also without the + // language module being installed. + // http://drupal.org/node/1749954 documents the new element. + $form['langcode'] = array( + '#type' => 'language_select', + '#title' => t('Menu language'), + '#languages' => LANGUAGE_ALL, + '#default_value' => $menu->langcode, + ); + if (module_exists('language')) { + $form['default_menu_items_language'] = array( + '#type' => 'details', + '#title' => t('Menu items language'), + ); + $form['default_menu_items_language']['default_language'] = array( + '#type' => 'language_configuration', + '#entity_information' => array( + 'entity_type' => 'menu_item', + 'bundle' => $menu->id(), + ), + '#default_value' => language_get_default_configuration('menu_item', $menu->id()), + ); + } + return $form; } @@ -76,10 +101,38 @@ protected function actions(array $form, array &$form_state) { $system_menus = menu_list_system_menus(); $actions['delete']['#access'] = !$menu->isNew() && !isset($system_menus[$menu->id()]); + // Add the language configuration submit handler. This is needed because + // the submit button has custom submit handlers. + if (module_exists('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 (module_exists('translation_entity')) { + array_unshift($actions['submit']['#submit'], 'translation_entity_language_configuration_element_submit'); + } return $actions; } /** + * Submit handler to update the bundle for the default language configuration. + */ + public function languageConfigurationSubmit(array &$form, array &$form_state) { + $menu = $this->getEntity($form_state); + // Delete the old language settings for the menu, if the machine name + // is changed. + if ($menu && $menu->id() && $menu->id() != $form_state['values']['id']) { + language_clear_default_configuration('menu_item', $menu->id()); + } + // 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']; + } + + /** * Overrides Drupal\Core\Entity\EntityFormController::save(). */ public function save(array $form, array &$form_state) { -- 1.7.12.4 (Apple Git-37)