Issue #2578173 by Peacog, maximpodorov, marvin_B8, andypost, alexpott, tatisilva: Increase menu title maxlength to 255 in forms containing menu items
parent
6badeae83c
commit
9fcdd308d8
|
@ -220,6 +220,7 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
|
||||||
'entity_id' => $menu_link->id(),
|
'entity_id' => $menu_link->id(),
|
||||||
'id' => $menu_link->getPluginId(),
|
'id' => $menu_link->getPluginId(),
|
||||||
'title' => $menu_link->getTitle(),
|
'title' => $menu_link->getTitle(),
|
||||||
|
'title_max_length' => $menu_link->getFieldDefinitions()['title']->getSetting('max_length'),
|
||||||
'description' => $menu_link->getDescription(),
|
'description' => $menu_link->getDescription(),
|
||||||
'menu_name' => $menu_link->getMenuName(),
|
'menu_name' => $menu_link->getMenuName(),
|
||||||
'parent' => $menu_link->getParentId(),
|
'parent' => $menu_link->getParentId(),
|
||||||
|
@ -229,10 +230,15 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$defaults) {
|
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(
|
$defaults = array(
|
||||||
'entity_id' => 0,
|
'entity_id' => 0,
|
||||||
'id' => '',
|
'id' => '',
|
||||||
'title' => '',
|
'title' => '',
|
||||||
|
'title_max_length' => $max_length,
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'menu_name' => $menu_name,
|
'menu_name' => $menu_name,
|
||||||
'parent' => '',
|
'parent' => '',
|
||||||
|
@ -313,6 +319,7 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) {
|
||||||
'#type' => 'textfield',
|
'#type' => 'textfield',
|
||||||
'#title' => t('Menu link title'),
|
'#title' => t('Menu link title'),
|
||||||
'#default_value' => $defaults['title'],
|
'#default_value' => $defaults['title'],
|
||||||
|
'#maxlength' => $defaults['title_max_length'],
|
||||||
);
|
);
|
||||||
|
|
||||||
$form['menu']['link']['description'] = array(
|
$form['menu']['link']['description'] = array(
|
||||||
|
|
|
@ -61,6 +61,11 @@ class MenuNodeTest extends WebTestBase {
|
||||||
$this->drupalGet('admin/structure/types/manage/page');
|
$this->drupalGet('admin/structure/types/manage/page');
|
||||||
$this->assertCacheContext('user.roles:authenticated');
|
$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.
|
// Disable the default main menu, so that no menus are enabled.
|
||||||
$edit = array(
|
$edit = array(
|
||||||
'menu_options[main]' => FALSE,
|
'menu_options[main]' => FALSE,
|
||||||
|
@ -171,6 +176,7 @@ class MenuNodeTest extends WebTestBase {
|
||||||
|
|
||||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||||
$this->assertFieldById('edit-menu-weight', 17, 'Menu weight correct in edit form');
|
$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.
|
// Disable the menu link, then edit the node--the link should stay disabled.
|
||||||
$link_id = menu_ui_get_menu_link_defaults($node)['entity_id'];
|
$link_id = menu_ui_get_menu_link_defaults($node)['entity_id'];
|
||||||
|
|
Loading…
Reference in New Issue