Problem/Motivation

When I add a new link in a menu and I select the parent link. The option list with the links appears truncated.

The function that truncate the title with a maximum of 30 characters is parentSelectOptionsTreeWalk in core/lib/Drupal/Core/Menu/MenuParentFormSelector.php. (Line 163)

$title = $indent . ' ' . Unicode::truncate($link->getTitle(), 30, TRUE, FALSE);

Does this limit exist for some special reason? And what would be the best way to override it?

Steps to reproduce

From #19

Steps to test -
1. Go to the admin site.
2. Go to admin/structure/menu/manage/admin/add?destination=/drupal9.1.x-dev/admin/structure/menu.
3. Create a menu link.
4. Again Go to admin/structure/menu/manage/admin/add?destination=/drupal9.1.x-dev/admin/structure/menu.
5. Verify the parent link field.

Proposed resolution

#24 :

we should just remove the truncation altogether.

Before:

After:

Remaining tasks

Write tests

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

None

CommentFileSizeAuthor
#58 test.png38.92 KBquietone
#56 interdiff_55-56.txt583 bytesjnlar
#56 1166282-56.patch2.06 KBjnlar
#55 1166282-55.patch2.08 KBjnlar
#55 interdiff_51-55.txt991 bytesjnlar
#52 After Patch.png90.78 KBprasanth_kp
#52 Before Patch.png102.19 KBprasanth_kp
#51 1166282-51.patch997 bytesmanojkumar_97
#51 1166282_50-51.txt571 bytesmanojkumar_97
#50 interdiff-1166282_39-50.txt701 bytesmanojkumar_97
#50 1166282-50.patch701 bytesmanojkumar_97
#49 1166282-after_patch.jpg59.09 KBgaurav-mathur
#49 1166282-patch_apply.jpg15.94 KBgaurav-mathur
#49 1166282-before_patch.jpg61.06 KBgaurav-mathur
#42 After-Patch-39.png177.04 KBManibharathi E R
#42 Before-patch-39.png178.06 KBManibharathi E R
#41 beforePatch.png688.31 KBPrem Suthar
#41 afterpatch.png538.5 KBPrem Suthar
#39 Titles-truncated-on-parent-menu-1166282-39.patch737 bytesRakhi Soni
#37 After Patch #30.png139.73 KByashingole
#37 Before Patch #30.png142.25 KByashingole
#34 1166282--after--patch--pic.png106.01 KBvikashsoni
#34 1166282--before--patch--pic.png234.67 KBvikashsoni
#32 patchafter.png112.2 KBRinku Jacob 13
#32 patchbefore.png110.73 KBRinku Jacob 13
#30 1166282-30.patch997 bytesKapilV
#29 1166282-29.patch998 bytesStockticker
#25 interdiff_7-25.txt877 bytesraman.b
#25 1166282-25.patch997 bytesraman.b
#22 1166282-after_patch-7.png55.29 KBAbhijith S
#22 1166282-before_patch.png60.8 KBAbhijith S
#19 After_2.png451.89 KBpriyanka.sahni
#19 Menu link.png85.26 KBpriyanka.sahni
#19 After.png371.45 KBpriyanka.sahni
#19 Before.png377.37 KBpriyanka.sahni
#7 drupal-titles_truncated_on_parent_menu-1166282-7-D8.patch731 bytesSagar Ramgade
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

juampynr’s picture

Subscribing. I would like to know the reason too.

Vacilando’s picture

A rather annoying issue. In dropdowns with just a few nested menus titles quickly become unintelligible.

Also unsure what's the best way to override this -- ideas?

taxicab221’s picture

I have had this same problem. After searching for a solution, came across this post, found the function you mentioned and changed the value to 60 with no apparent side effects. Will update this post if I come across any problems.

If anyone can point me in the right direction as to if this function can be moved into the sites/modules or sites/theme folders and be rewritten as an override function, then that would be very much appreciated.

steinmb’s picture

I think there is no other way then to copy the entire code into your own custom menu module and maintain it there. I did not find a other way of solving it. I moved these functions.

function menu_form_node_form_alter(&$form, $form_state) {}
function menu_parent_options($menus, $item, $type = '') {}
function _menu_get_options($menus, $available_menus, $item) {}
function _menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, $depth_limit) {}
kumkum29’s picture

Issue summary: View changes

Hello steinmb,

how do you implement these functions in your custom module? You modify the names?
Can we use theses functions in the template.php file of the admin theme?
Finaly, have you found a more simplest solution for alter the number of characters?

Thanks for your help.

hansrossel’s picture

Version: 7.x-dev » 8.1.x-dev
Category: Support request » Feature request

Really very annoying, 30 is too short, should be at least 60 or 72 by default.

Seems like Drupal 8 also has this limit:
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Menu!MenuParentFo...

Sagar Ramgade’s picture

Status: Active » Needs review
FileSize
731 bytes

It seems 60 characters is the decent limit, Patch attached changes the value to 60.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Sivaji_Ganesh_Jojodae’s picture

Retest requested to see if the patch is still good.

priyanka.sahni’s picture

Assigned: Unassigned » priyanka.sahni
priyanka.sahni’s picture

FileSize
377.37 KB
371.45 KB
85.26 KB
451.89 KB

Verified and tested by applying the patch.It was applied successfully.It looks good to me.Can be moved to RTBC.

Steps to test -
1. Go to the admin site.
2. Go to admin/structure/menu/manage/admin/add?destination=/drupal9.1.x-dev/admin/structure/menu.
3. Create a menu link.
4. Again Go to admin/structure/menu/manage/admin/add?destination=/drupal9.1.x-dev/admin/structure/menu.
5. Verify the parent link field.

Menu

Before Patch -
BeforePatch

After Patch -
After Patch

After Patch

priyanka.sahni’s picture

Assigned: priyanka.sahni » Unassigned

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Abhijith S’s picture

Applied patch #7 and it works fine. I've added the word 'pneumonoultramicroscopicsilicovolcanoconiosis' as menu title and it comes normally as truncated in the parent link section.After applying this patch this problem is resolved.Adding screenshots below

before:
before

after patch:
after

Abhijith S’s picture

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

Category: Feature request » Task
Status: Reviewed & tested by the community » Needs work

The truncation was added in #151583: Menu - Fixes that make menu module work in D6 back in 2007. This was an omnibus patch fixing several issues in the menu system (while it was being rewritten), but where the 30 char truncation wasn't mentioned in the discussion.

Rather than increasing it to 60, I think we should just remove the truncation altogether.

raman.b’s picture

Status: Needs work » Needs review
FileSize
997 bytes
877 bytes

Removing the truncation from parentSelectOptionsTreeWalk

steinmb’s picture

Status: Needs review » Reviewed & tested by the community

Looks right to me.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

Sorry folks, this needs an IS update. It should include, at least, the proposed resolution. And up to date before and after screenshots will help as well.

I don't know but does this need a test?

raman.b’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update +Needs tests

Applying IS template and tagging for tests

Stockticker’s picture

FileSize
998 bytes

Re-roll for a Drupal 8.9.x.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Rinku Jacob 13’s picture

FileSize
110.73 KB
112.2 KB

Verified and tested patch#30 on the drupal 9.3.x-dev version. Patch applied successfully and looks good to me.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

vikashsoni’s picture

Applied patch #30 applied in drupal-9.3.x-dev applied successfully
After patch the width of select container auto set according to text

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

yashingole’s picture

Assigned: Unassigned » yashingole
yashingole’s picture

Assigned: yashingole » Unassigned
Status: Needs review » Reviewed & tested by the community
FileSize
142.25 KB
139.73 KB

Verified and tested patch #30 on Drupal 9.5.x-dev. Patch applied successfully and looks good to me.
Testing steps:
1. Go to the admin site.
2. Go to admin/structure/menu/manage/main/add?destination=/d9.5/admin/structure/menu/manage/main.
3. Create a menu link.
4. Again Go to admin/structure/menu/manage/main/add?destination=/d9.5/admin/structure/menu/manage/main.
5. Verify the parent link field.
Testing Result:
1. After applying the patch the parent link is not truncated.
Can be move to RTBC

quietone’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update, +Novice

This is a nice wee improvement!

Just a few things to do before this is ready for a committer.

Following the process in Triage the Drupal core RTBC queue to review this issue.

3. The issue title is a statement of the problem, probably better as the fix. 'Remove truncation from parent menu'
4. The issue summary is clear and mostly accurate. The remaining tasks says this this needs tests and this is tagged for tests. There are no tests in the patch nor any discussion of whether a test is needed or not. The screenshots are out of date, they are from #19 and the patch has changed since then and so has the default admin theme.
5. Needs a decision on testing in order to pass the Testing gate.

Based on the above points setting back to NW.

Duplicate sets of screenshots have been added for that same patch, removing credit for #22, #34.

The work here is suitable as a novice task, adding tag.

Rakhi Soni’s picture

Status: Needs work » Needs review
FileSize
737 bytes

Attached rerolled patch against drupal version 9.5x,,
Please review...

Prem Suthar’s picture

FileSize
538.5 KB
688.31 KB

Verified and tested patch#30,Patch#39 and Patch#25 on the drupal 9.5.x-dev version. Patch applied successfully and looks good to me.We can move to RTBC.

Manibharathi E R’s picture

FileSize
178.06 KB
177.04 KB

Patch #39 Applied successfully on Drupal 9.5.x.

bnjmnm’s picture

Status: Needs review » Needs work

#30 still applies to 9.5, there's no need for the reroll in #39 and the issue should not be changed from "needs work" to "needs review" unless the work requested has been completed. Even if it was a necessary reroll, there's no need to review it as it's effectively the same already-reviewed patch.

joseph.olstad’s picture

Title: Titles truncated on parent menu » Remove truncation from parent menu
joseph.olstad’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

all that's left is to add a very simple parent item menu link title length longer than 30 characters assertion in the menu system tests for this

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

sahil.goyal’s picture

Patch is does not have any major changes so it still applies for the version 10.1.x as being said there would not been any requirement to reroll the patch. even i tried to apply the patch it applied successfully and work as expected.

gaurav-mathur’s picture

Assigned: Unassigned » gaurav-mathur
gaurav-mathur’s picture

Assigned: gaurav-mathur » Unassigned
Status: Needs work » Reviewed & tested by the community
FileSize
61.06 KB
15.94 KB
59.09 KB

Hi apply the patch#39 on drupal 10.1.x-dev it applied successfully and work as expected. there would not been any requirement to reroll the patch.
adding screenshot for the reference.
We can move to RTBC.
Thank You

manojkumar_97’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
701 bytes
701 bytes

I have created a patch against #39 drupal version 10.1.x. We need to remove truncation from parent menu not truncation limit increment according the query.
pls review ...

manojkumar_97’s picture

prasanth_kp’s picture

FileSize
102.19 KB
90.78 KB

#51 Patch Applied on 10.1.x-dev and work as expected.

manojkumar_97’s picture

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

Status: Reviewed & tested by the community » Needs work

Issue tagged with "needs tests" and I find no tests in #51.

jnlar’s picture

Status: Needs work » Needs review
FileSize
991 bytes
2.08 KB

Attached a patch adding a functional test. I've put the test in MenuUiTest since it seemed like the appropriate place. The test won't pass if you don't apply the patch from #51

Please review!

jnlar’s picture

Fixed failed CSpell test

ameymudras’s picture

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

Tested the above patch on 10.1.x

1. The issue summary is clear and steps to reproduce have been provided with screenshots
2. Was able to reproduce the issue
3. The patch applies cleanly and fixes the issue with menu item truncation
4. Did a code review and no issues were identified
5. Tests have been provided

The before after screenshots have been provided above and not much has changed since so avoiding these again. Looks good for RTBC

quietone’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: -Novice +Needs usability review
FileSize
38.92 KB

I read the Issue Summary. I do not see any difference between the before and after screen shots. I am missing something. If so, perhaps a comment to help the reviewer.

I applied that patch and tested by making an extremely long menu link. The result is not very friendly. I do like that in ends in an ellipsis. See the attached screenshot. Is removing truncation the best option here? I now think this needs a usability review. Adding tag.

+++ b/core/modules/menu_ui/tests/src/Functional/MenuUiTest.php
@@ -1141,4 +1141,22 @@ public function testMenuUiWithPendingRevisions() {
+  public function testMenuParentFormSelect() {

This test is only adding a link so it can be added to an existing test. That will allow us to not increase testing time and cost. I did not look closely but \Drupal\Tests\menu_ui\Functional\MenuUiTest::addMenuLink looks like a possible choice.

bnjmnm’s picture

Issue summary: View changes

The before and after in the issue summary were referencing the same image. I updated the "after" to reference the image intended to be shown there. Note that the screenshot in #58 shows that there may be other "after" scenarios to consider beyond the ideal-scenario one presented in the IS.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.