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.
| Comment | File | Size | Author |
|---|---|---|---|
| #52 | interdiff.txt | 1.5 KB | David_Rothstein |
| #52 | D7-menu_title_maxlenth-2578173-52-tests-only.patch | 1.33 KB | David_Rothstein |
| #52 | D7-menu_title_maxlenth-2578173-52.patch | 2.27 KB | David_Rothstein |
| #38 | interdiff-2578173-34-38.txt | 1.37 KB | peacog |
| #38 | D7-menu_title_maxlenth-2578173-38.patch | 2.38 KB | peacog |
Comments
Comment #2
maximpodorov commentedComment #3
andypostD8 is not affected
Comment #4
omkar06 commentedPatch tested with drupal's 7.x latest code. Its perfectly working. I am able to add menu title to length 255.
Comment #5
David_Rothstein commentedIn Drupal 8 on the node form (I didn't check anywhere else) I see this:
So maxlength = 128 still in Drupal 8.
Comment #6
snehi commentedIn Drupal 8 i think it already 255. PFA Screenshot.

Comment #7
snehi commentedIt 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.
Comment #8
maximpodorov commentedBack to normal state.
Comment #9
andypostin D8 actually only node-edit form is affected as #5 said
Comment #10
marvin_b8 commentedthe patch is really,really simple =)
Comment #11
andypostNice! but this "max length" should be taken from title field definition, like #6 shows
Comment #12
peacog commentedI'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.
Comment #13
andypostThanx! that looks a solution but the array of defaults should be the same depth, just add another key for 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
would be create to prevent entity create because this affects performance seriously
changing this structure is APi change that is not allowed at RC stage
so let's keep the defaults just extended with with "title_max_length"
Comment #14
peacog commentedThanks 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.
Comment #16
peacog commentedAh, failed the testbot. Let's try this one.
Comment #17
andypostYep, that's better.
About tests, suppose you just need to add few lines to
\Drupal\menu_ui\Tests\MenuTest::doMenuLinkFormDefaultsTestComment #18
peacog commentedUnhiding last patch
Comment #19
peacog commentedOK, 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.
Comment #20
andypostLooks great now!
Comment #21
maximpodorov commentedThank me for finding the problem. :)
Comment #23
peacog commentedSetting back to Needs review to prompt testbot.
Comment #24
peacog commentedTestbot is happy again, so setting back to RTBC
Comment #26
peacog commentedReapplied patch and tested locally and all is well, so this looks like a testbot glitch. Submitting for retest.
Comment #27
peacog commentedAnd back to RTBC
Comment #28
alexpottThis 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.
Comment #29
tatisilva commentedI have created change record. https://www.drupal.org/node/2659678
Comment #30
andypostCR looks good
Comment #31
alexpottCommitted 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
Comment #34
maximpodorov commentedSo the patch for D7 returns.
Comment #36
maximpodorov commentedTests are passed.
Comment #37
andypostthis tests should be backported as well
Comment #38
peacog commentedHere's a patch that includes the backported tests.
Comment #39
Pradnya Pingat commentedreview in progress
Comment #40
Pradnya Pingat commentedComment #41
Pradnya Pingat commentedComment #42
fabianx commentedI 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.
Comment #43
stefan.r commentedFiled #2756723: Add tests for increased menu title maxlength to 255 in forms containing menu items
Comment #44
stefan.r commentedComment #45
Patil_kunal27 commentedupdated title maxlength to 255
Comment #47
fabianx commented#45: Thank you, but the patch in #38 already passed review and your patch lacks tests.
Comment #49
fabianx commentedComment #51
fabianx commented#38 needs a reroll including tests.
Comment #52
David_Rothstein commentedI 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.
Comment #54
David_Rothstein commentedThose look like the correct passes/fails, so moving this back to RTBC.
Comment #55
stefan.r commentedTested that this correctly changes the maxlength to 255 in the node form and menu link form.
Committed and pushed to 7.x, thanks!
Comment #57
stefan.r commented