Issue #2578173 by Peacog, maximpodorov, marvin_B8, andypost, alexpott, tatisilva: Increase menu title maxlength to 255 in forms containing menu items

8.1.x
Alex Pott 2016-02-04 11:36:51 +00:00
parent 6badeae83c
commit 9fcdd308d8
2 changed files with 13 additions and 0 deletions

View File

@ -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(

View File

@ -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('/<input .* id="edit-menu-title" .* maxlength="' . $max_length . '" .* \/>/', '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('/<input .* id="edit-menu-title" .* maxlength="' . $max_length . '" .* \/>/', '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'];