Commit a07de444 authored by catch's avatar catch

Issue #2852665 by Rajender Rajan, monta, arshadcn, Vj, dpc-vic, ivrh, rajibmp:...

Issue #2852665 by Rajender Rajan, monta, arshadcn, Vj, dpc-vic, ivrh, rajibmp: No validation on text length for menu description when editing node

(cherry picked from commit e03863f6)
parent bf5258ec
......@@ -176,6 +176,7 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
'title' => $menu_link->getTitle(),
'title_max_length' => $menu_link->getFieldDefinitions()['title']->getSetting('max_length'),
'description' => $menu_link->getDescription(),
'description_max_length' => $menu_link->getFieldDefinitions()['description']->getSetting('max_length'),
'menu_name' => $menu_link->getMenuName(),
'parent' => $menu_link->getParentId(),
'weight' => $menu_link->getWeight(),
......@@ -188,12 +189,14 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
// definition.
$field_definitions = \Drupal::entityManager()->getBaseFieldDefinitions('menu_link_content');
$max_length = $field_definitions['title']->getSetting('max_length');
$description_max_length = $field_definitions['description']->getSetting('max_length');
$defaults = [
'entity_id' => 0,
'id' => '',
'title' => '',
'title_max_length' => $max_length,
'description' => '',
'description_max_length' => $description_max_length,
'menu_name' => $menu_name,
'parent' => '',
'weight' => 0,
......@@ -277,11 +280,11 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) {
];
$form['menu']['link']['description'] = [
'#type' => 'textarea',
'#type' => 'textfield',
'#title' => t('Description'),
'#default_value' => $defaults['description'],
'#rows' => 1,
'#description' => t('Shown when hovering over the menu link.'),
'#maxlength' => $defaults['description_max_length'],
];
$form['menu']['link']['menu_parent'] = $parent_element;
......
......@@ -63,9 +63,14 @@ public function testMenuNodeFormWidget() {
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Contexts', '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');
$title_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.');
$this->assertPattern('/<input .* id="edit-menu-title" .* maxlength="' . $title_max_length . '" .* \/>/', 'Menu link title field has correct maxlength in node add form.');
// Verify that the menu link description has the correct maxlength.
$description_max_length = \Drupal::entityManager()->getBaseFieldDefinitions('menu_link_content')['description']->getSetting('max_length');
$this->drupalGet('node/add/page');
$this->assertPattern('/<input .* id="edit-menu-description" .* maxlength="' . $description_max_length . '" .* \/>/', 'Menu link description field has correct maxlength in node add form.');
// Disable the default main menu, so that no menus are enabled.
$edit = [
......@@ -175,7 +180,8 @@ public function testMenuNodeFormWidget() {
$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.');
$this->assertPattern('/<input .* id="edit-menu-title" .* maxlength="' . $title_max_length . '" .* \/>/', 'Menu link title field has correct maxlength in node edit form.');
$this->assertPattern('/<input .* id="edit-menu-description" .* maxlength="' . $description_max_length . '" .* \/>/', 'Menu link description field has correct maxlength in node add 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'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment