Forms in menu_edit_item() and menu_form_node_form_alter() functions do not specify #maxlength for menu link titles, so the default of 128 characters is used. Menu item title can contain 255 characters as defined in 'menu_links' DB table schema. So the limitation of 128 characters is meaningless (set by Form API defaults), and I suggest to set #maxlength to 255 explicitly in forms containing menu link titles.

Comments

maximpodorov created an issue. See original summary.

maximpodorov’s picture

Status: Active » Needs review
StatusFileSize
new962 bytes
andypost’s picture

Issue tags: +Needs tests

D8 is not affected

omkar06’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests +Reviewed

Patch tested with drupal's 7.x latest code. Its perfectly working. I am able to add menu title to length 255.

David_Rothstein’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs backport to D7

In Drupal 8 on the node form (I didn't check anywhere else) I see this:

<label for="edit-menu-title">Menu link title</label>
<input type="text" class="form-text" maxlength="128" size="60" value="" name="menu[title]" id="edit-menu-title" data-drupal-selector="edit-menu-title">

So maxlength = 128 still in Drupal 8.

snehi’s picture

StatusFileSize
new26.98 KB

In Drupal 8 i think it already 255. PFA Screenshot.
screesnhot

snehi’s picture

Assigned: Unassigned » snehi
Status: Needs work » Closed (works as designed)

It is already working as designed.
Title length is 255 and is working fine in drupal 8 dev version.
Have any query. Feel free to reopen this issue.

maximpodorov’s picture

Assigned: snehi » Unassigned
Status: Closed (works as designed) » Needs work

Back to normal state.

andypost’s picture

Issue summary: View changes
Issue tags: -Reviewed +Novice
StatusFileSize
new31.15 KB

in D8 actually only node-edit form is affected as #5 said

marvin_b8’s picture

Status: Needs work » Needs review
StatusFileSize
new492 bytes

the patch is really,really simple =)

andypost’s picture

Issue tags: +Needs tests

Nice! but this "max length" should be taken from title field definition, like #6 shows

peacog’s picture

StatusFileSize
new1.77 KB

I'm trying to figure out the right way to grab the max_length setting from the field definition, as per @andypost's comment. I don't know if this is the right approach to take, but it seems like this could be done by getting the default max_length setting from the base field definition in menu_ui_get_menu_link_defaults(). Here's a patch that does that.

andypost’s picture

Status: Needs review » Needs work

Thanx! that looks a solution but the array of defaults should be the same depth, just add another key for max length

  1. +++ b/core/modules/menu_ui/menu_ui.module
    @@ -219,7 +219,10 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
    +        'title' => array(
    +          'title' => $menu_link->getTitle(),
    +          'max_length' => $menu_link->getFieldDefinitions()['title']->getSetting('max_length'),
    

    that looks strange at least...
    maybe title and title_max_length is a better naming ... and better to keep them on the same level

  2. +++ b/core/modules/menu_ui/menu_ui.module
    @@ -229,10 +232,17 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
    +    $menu_link = MenuLinkContent::create();
    +    $max_length = $menu_link->getFieldDefinitions()['title']->getSetting('max_length');
    

    would be create to prevent entity create because this affects performance seriously

  3. +++ b/core/modules/menu_ui/menu_ui.module
    @@ -229,10 +232,17 @@ function menu_ui_get_menu_link_defaults(NodeInterface $node) {
    -      'title' => '',
    +      'title' => array(
    +        'title' => '',
    +        'max_length' => $max_length,
    

    changing this structure is APi change that is not allowed at RC stage

  4. +++ b/core/modules/menu_ui/menu_ui.module
    @@ -312,7 +322,8 @@ function menu_ui_form_node_form_alter(&$form, FormStateInterface $form_state) {
    -    '#default_value' => $defaults['title'],
    +    '#default_value' => $defaults['title']['title'],
    +    '#maxlength' => $defaults['title']['max_length'],
    

    so let's keep the defaults just extended with with "title_max_length"

peacog’s picture

Status: Needs work » Needs review
StatusFileSize
new1.55 KB
new1.89 KB

Thanks for reviewing! OK, I've implemented all your suggestions. Hopefully this one is better.

As for tests, I haven't created any test before so I'm not sure how to go about it. Should I add a new test file in core/modules/menu_ui/src/Tests? Could you point me in the direction of another similar test I can copy, and I'll have a go at creating a test for this? Thanks.

Status: Needs review » Needs work

The last submitted patch, 14: menu-title-maxlength-2578173-14.diff, failed testing.

peacog’s picture

StatusFileSize
new1.55 KB
new620 bytes

Ah, failed the testbot. Let's try this one.

andypost’s picture

Status: Needs work » Needs review

Yep, that's better.
About tests, suppose you just need to add few lines to \Drupal\menu_ui\Tests\MenuTest::doMenuLinkFormDefaultsTest

peacog’s picture

Unhiding last patch

peacog’s picture

StatusFileSize
new1.34 KB
new3 KB

OK, I've added a couple of tests to \Drupal\menu_ui\Tests\MenuNodeTest::testMenuNodeFormWidget, since this patch affects the menu link on the node add and edit forms only. The tests use assertPattern to search for an input element with id="edit-menu-title" and maxlength=the maxlength setting pulled from the base field definition.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks great now!

maximpodorov’s picture

Thank me for finding the problem. :)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: menu-title-maxlength-2578173-19.diff, failed testing.

peacog’s picture

Status: Needs work » Needs review

Setting back to Needs review to prompt testbot.

peacog’s picture

Status: Needs review » Reviewed & tested by the community

Testbot is happy again, so setting back to RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: menu-title-maxlength-2578173-19.diff, failed testing.

peacog’s picture

Status: Needs work » Needs review

Reapplied patch and tested locally and all is well, so this looks like a testbot glitch. Submitting for retest.

peacog’s picture

Status: Needs review » Reviewed & tested by the community

And back to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs tests +Needs change record

This fix is done in a backwards compatible manor and has test coverage. As this is fixing a bug because it possible to create long menu titles through the API and then no be able to edit in the UI we should commit this to 8.0.x. However given that other entities might implement a similar integration with menu links as Node does I think this is worth a change record - https://www.drupal.org/node/add/changenotice?field_project=3060.

tatisilva’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

I have created change record. https://www.drupal.org/node/2659678

andypost’s picture

Status: Needs review » Reviewed & tested by the community

CR looks good

alexpott’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed b6f1612 and pushed to 8.0.x and 8.1.x. Thanks!

I rewrote the CR to focus on informing people about why we made the change and how a module might want to change their code to follow suit. https://www.drupal.org/node/2659678/revisions/view/9332968/9341898

  • alexpott committed 9fcdd30 on
    Issue #2578173 by Peacog, maximpodorov, marvin_B8, andypost, alexpott,...

  • alexpott committed b6f1612 on
    Issue #2578173 by Peacog, maximpodorov, marvin_B8, andypost, alexpott,...
maximpodorov’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new962 bytes

So the patch for D7 returns.

Status: Needs review » Needs work

The last submitted patch, 34: D7-menu_title_maxlenth-2578173-34.patch, failed testing.

maximpodorov’s picture

Status: Needs work » Needs review

Tests are passed.

andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
+++ b/core/modules/menu_ui/src/Tests/MenuNodeTest.php
@@ -61,6 +61,11 @@ function testMenuNodeFormWidget() {
+    $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.');

@@ -171,6 +176,7 @@ function testMenuNodeFormWidget() {
+    $this->assertPattern('/<input .* id="edit-menu-title" .* maxlength="' . $max_length . '" .* \/>/', 'Menu link title field has correct maxlength in node edit form.');

this tests should be backported as well

peacog’s picture

Status: Needs work » Needs review
StatusFileSize
new2.38 KB
new1.37 KB

Here's a patch that includes the backported tests.

Pradnya Pingat’s picture

Assigned: Unassigned » Pradnya Pingat

review in progress

Pradnya Pingat’s picture

Status: Needs review » Reviewed & tested by the community
Pradnya Pingat’s picture

Issue tags: -Novice, -Needs backport to D7, -Needs tests ++drupalconasia2016
fabianx’s picture

Issue tags: -+drupalconasia2016 +drupalconasia2016, +Pending Drupal 7 commit

I think we miss test coverage in both D8 and D7 for the menu edit item screen.

Can we open a follow-up for that (as a child of this issue).

RTBC + 1, marked for commit.

stefan.r’s picture

Assigned: Pradnya Pingat » Unassigned
Patil_kunal27’s picture

StatusFileSize
new984 bytes

updated title maxlength to 255

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 45: D7-menu_title_max_valid-2578173-44.patch, failed testing.

fabianx’s picture

Status: Needs work » Reviewed & tested by the community

#45: Thank you, but the patch in #38 already passed review and your patch lacks tests.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 45: D7-menu_title_max_valid-2578173-44.patch, failed testing.

fabianx’s picture

Status: Needs work » Reviewed & tested by the community

The last submitted patch, 38: D7-menu_title_maxlenth-2578173-38.patch, failed testing.

fabianx’s picture

Issue tags: +Needs reroll

#38 needs a reroll including tests.

David_Rothstein’s picture

Issue tags: -Pending Drupal 7 commit, -Needs reroll +7.50 release notes
StatusFileSize
new2.27 KB
new1.33 KB
new1.5 KB

I don't think it actually needed a reroll, but I noticed that the new test code was trying (and failing) to create a node for no reason - which also doesn't match what the Drupal 8 patch was doing. So I fixed that plus a code comment fix.

This should be good to go as long as the tests pass/fail as expected.

After commit we could create a Drupal 7 change notice similar to https://www.drupal.org/node/2659678, although I think a release notes + CHANGELOG mention might be enough for this also.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 52: D7-menu_title_maxlenth-2578173-52-tests-only.patch, failed testing.

David_Rothstein’s picture

Status: Needs work » Reviewed & tested by the community

Those look like the correct passes/fails, so moving this back to RTBC.

stefan.r’s picture

Tested that this correctly changes the maxlength to 255 in the node form and menu link form.

Committed and pushed to 7.x, thanks!

  • stefan.r committed 5e71cae on 7.x
    Issue #2578173 by Peacog, David_Rothstein, maximpodorov, marvin_B8,...
stefan.r’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.