From 9fcdd308d812d00baf482b79bff0f3eb59687746 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Thu, 4 Feb 2016 11:36:51 +0000 Subject: [PATCH] Issue #2578173 by Peacog, maximpodorov, marvin_B8, andypost, alexpott, tatisilva: Increase menu title maxlength to 255 in forms containing menu items --- core/modules/menu_ui/menu_ui.module | 7 +++++++ core/modules/menu_ui/src/Tests/MenuNodeTest.php | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/core/modules/menu_ui/menu_ui.module b/core/modules/menu_ui/menu_ui.module index 7c01f6fe0f8..f32608cba8e 100644 --- a/core/modules/menu_ui/menu_ui.module +++ b/core/modules/menu_ui/menu_ui.module @@ -220,6 +220,7 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) { 'entity_id' => $menu_link->id(), 'id' => $menu_link->getPluginId(), 'title' => $menu_link->getTitle(), + 'title_max_length' => $menu_link->getFieldDefinitions()['title']->getSetting('max_length'), 'description' => $menu_link->getDescription(), 'menu_name' => $menu_link->getMenuName(), 'parent' => $menu_link->getParentId(), @@ -229,10 +230,15 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) { } if (!$defaults) { + // Get the default max_length of a menu link title from the base field + // definition. + $field_definitions = \Drupal::entityManager()->getBaseFieldDefinitions('menu_link_content'); + $max_length = $field_definitions['title']->getSetting('max_length'); $defaults = array( 'entity_id' => 0, 'id' => '', 'title' => '', + 'title_max_length' => $max_length, 'description' => '', 'menu_name' => $menu_name, 'parent' => '', @@ -313,6 +319,7 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) { '#type' => 'textfield', '#title' => t('Menu link title'), '#default_value' => $defaults['title'], + '#maxlength' => $defaults['title_max_length'], ); $form['menu']['link']['description'] = array( diff --git a/core/modules/menu_ui/src/Tests/MenuNodeTest.php b/core/modules/menu_ui/src/Tests/MenuNodeTest.php index b3397cc6522..b57cc9d1ee6 100644 --- a/core/modules/menu_ui/src/Tests/MenuNodeTest.php +++ b/core/modules/menu_ui/src/Tests/MenuNodeTest.php @@ -61,6 +61,11 @@ class MenuNodeTest extends WebTestBase { $this->drupalGet('admin/structure/types/manage/page'); $this->assertCacheContext('user.roles:authenticated'); + // Verify that the menu link title has the correct maxlength. + $max_length = \Drupal::entityManager()->getBaseFieldDefinitions('menu_link_content')['title']->getSetting('max_length'); + $this->drupalGet('node/add/page'); + $this->assertPattern('//', 'Menu link title field has correct maxlength in node add form.'); + // Disable the default main menu, so that no menus are enabled. $edit = array( 'menu_options[main]' => FALSE, @@ -171,6 +176,7 @@ class MenuNodeTest extends WebTestBase { $this->drupalGet('node/' . $node->id() . '/edit'); $this->assertFieldById('edit-menu-weight', 17, 'Menu weight correct in edit form'); + $this->assertPattern('//', 'Menu link title field has correct maxlength in node edit form.'); // Disable the menu link, then edit the node--the link should stay disabled. $link_id = menu_ui_get_menu_link_defaults($node)['entity_id'];