The Standard installation profile creates a useful "Home" menu link, but it is hard-coded. When a user wants to edit it, the following message is displayed:
This link is provided by the Standard module. The title and path cannot be edited.
This is hardly user-friendly. The only way around this is for the user to disable the Home link and create a new one instead and pointing it to <front>.
My proposal is to create the menu link programmatically and making it editable/deletable.
Comments
Comment #2
wmostrey commentedComment #4
wmostrey commentedHere's a patch that fixes the last two fails but I don't know how/where to fix the first two:
1.
2.
"There is content for the entity type: Custom menu link. Remove custom menu link entities."Comment #5
tstoecklerI think this generally makes a lot of sense, but since there is nothing dynamic in this link, I think the code should be moved to
standard_install()instead.Comment #6
wmostrey commentedThat makes sense. This patch should also fix two fails, with two remaining.
Comment #8
tstoecklerConfigImportAllTest::testInstallUninstall()already contains:so I guess we need to add similar code for menu links.
Comment #9
wmostrey commentedThanks for the guidance. Attached patch should fix this.
Comment #10
berdirIn general +1, that's exactly what I suggested we should do in #2710469: Move contact module footer link to standard install profile.
wait, what? we're testing that an the *install profile* can be uninstalled? Since when can we do that?
Home should use t(). Not sure about internal:/, but I guess that's correct here, using routes and so on is technically possible but again makes editing tricky.
Comment #11
wmostrey commented'internal:/'is the only way to get a link to<front>.Comment #12
berdir1. No, it is definitely not the scope of this issue. titles in links.menu.yml files *are* translatable, that means you moving it to standard_install() makes it untranslatable and it was before.
Comment #13
wmostrey commentedWould it be enough to add a langcode?
Comment #14
tstoecklerRe @wmostrey, no the langcode should not be added, that will be automatically determined to be the default site language.
You just have to change
'Home'into
t('Home')Comment #15
wmostrey commentedHere we go.
Comment #16
tstoecklerThanksy looks great. I have one more comment on this, do you mind re-rolling once more:
The only quibble I have with this is the variable name
$homefor something that is an *array* of menu links. Can we name it$menu_linksinstead?Not sure if we then want to update the comment above it as well (i.e. "Delete any menu links" instead of "Delete the home menu item"), but I think a better variable name would make it sufficiently clear either way.
Comment #17
wmostrey commentedGood idea.
Comment #18
tstoecklerThanks for sticking with this, looks great to me now!
Comment #20
berdirThis comment is wrong, only noticed now why that confusd me so before.
install profiles can not be uninstalled and we are not doing that.
*but*, menu_link_content is and can be uninstalled. And that's what's not possible without deleting them.
See preUninstallForum() and how it is called, I think we should use the same pattern.
Actually a bit surprised why shortcut doesn't need this, we also create shortcut entities in standard? How is this even related to standard_install(), this test isn't based on standard?
something is wrong here..
Comment #21
wmostrey commentedSo where do you think the following code (with adjusted comment) should live?
Also in
InstallUninstallTest.php?Comment #22
berdirIf the code is needed then in a preUninstallMenuLinkContent().
But see the second part, I do not understand why it is necessary at all. The forum part is necessary because forum_install() itself creates the menu link. But standard_install() never runs as part of that test, or we'd have exactly the same problem for shortcuts too?
Comment #23
berdirSorry I misread that. We do delete shortcuts above that. The only thing that's not correct is the comment, which should say so the menu_link_content module can be uninstalled.
Comment #24
wmostrey commentedHere we go.
Comment #25
berdirThanks, sorry again for the confusion on my side :)
Comment #26
alexpottThis needs an upgrade path - without one existing standard installs will lose their home link :)
Comment #27
wmostrey commentedSomething like this?
Comment #28
wmostrey commentedHm that won't work for people who clear the cache before running update.php.
Comment #29
wmostrey commentedI'm thinking about doing something like this, upon first cache clear. If the 'standard.front_page' menu item still exists in cache, take its settings (weight and enabled) and create the dynamic link. When the cache clear is ready, the 'standard.front_page' menu item has ceased to exist.
How do you feel about this implementation?
Comment #30
berdirAs commented in the drupal answers questions, I don't think anything like that will work because your hook won't exist until a cache clear, and then the menu cache is gone already.
But a cache is just a cache, we *never* store something only in cache. IIRC, we store the information on whether a menu link was enabled and its exact overriden configuration in... configuration. See \Drupal\Core\Menu\StaticMenuLinkOverrides,
Comment #31
wmostrey commentedI implemented an interesting idea by borisson_: leave the
standard.links.menu.ymlbe. So we create a new dynamic "Home" link with the weight and status of the static one, and we simply disable the static "Home" link.The problem is that on a new install, you have two "Home" links: one enabled dynamic link, and one disabled status link. I'm not quite sure how to proceed from here, input is welcome.
Comment #32
anita verma commentedComment #33
wmostrey commentedComment #34
wmostrey commentedWe have two options:
1. Static Home menu item wasn't altered. After deleting standard.links.menu.yml and clearing cache, the static Home menu item disappears. Let's use the default options for our new dynamic menu item (weight 0 and enabled).
2. Static Home menu item was altered (by disabling/enabling it or changing weight). After deleting standard.links.menu.yml and clearing cache, the static Home menu item is still there. Let's use its values for our new dynamic menu item, and disable the static menu item since we can't delete it.
Comment #35
wmostrey commentedI submitted a bug at #2847653: Orphaned menu items should support removeDefinition because we can't remove the
standard.front_pagemenu item.Comment #36
Saphyel commentedWhy do you create a cache and then you delete it?
Comment #37
Saphyel commentedComment #38
tstoecklerThanks for opening that bug report. Very interesting that that doesn't work. So should this be postponed on that then?
Comment #39
wmostrey commentedI'm afraid so yes.
The only alternative is that, if someone changed the static menu item, to let the now orphaned menu item exist in a disabled state. That leaves us with a disable menu item that has a "reset" option that results in a fatal error. And seeing that the original intent of this issue was to make things more user friendly, I don't think that's an option.
Comment #40
tstoecklerThe alternative would be that we use
\Drupal::configFactory()->getEditable('core.menu.static_menu_link_overrides')to load the override config directly and modify it. Have you tried that?Comment #41
wmostrey commentedAs far as I can see this still doesn't allow us to delete the item, not with
->delete()or->clear()->save()(I'm available at #drupal-contribute during the #SprintWeekend to work on this.)
Comment #42
tstoecklerNot on IRC today unfortunately, I might take a look at this later, though.
Comment #44
CatsFromStonehenge commentedHi.
How did you get on with this patch? Is it live?
I'm having a huge problem getting rid of such a menu item. If I try to edit the menu item, I'm told "This link is provided by the Standard module. The title and path cannot be edited". I removed the entry from the database, but when I clear the caches, it comes back!
Most suggested workarounds didn't work to get rid of it. Although, maybe I didn't execute the workarounds correctly.
I'm open to helping, although I've only been using Drupal for about 2 weeks, if that.
Thanks for looking into a fix :) Appreciated :)
Comment #45
CatsFromStonehenge commentedI've added an issue report here: https://www.drupal.org/node/2859921#comment-11982233
I gave my input as a noob (< 2 weeks on Drupal). A better warning message might also be a good idea, especially to help us noobs on our way.
Thanks again for all your hard work :)
Comment #46
wmostrey commentedHi @CatsFromStonehenge, thank you for your input. The solution we're aiming for is not to make a better warning message but to make the Home menu item editable/deletable just like any other menu item. We're still working on this though.
Comment #47
Pavan B S commentedRerolled the patch and change short array
Comment #48
akashkrishnan01 commentedComment #49
akashkrishnan01 commentedPavan B S, your patch is getting applied but I cannot see any changes with the warning, it still shows the same message *This link is provided by the Standard module. The title and path cannot be edited.*. Please describe the working of your patch too. Thanks for the re-roll.
Comment #50
wmostrey commented@akashkrishnan It's a reroll of my patch. You need to run update.php after applying it. Do note we still have the issues described in #34 and the open bug report in #35.
Comment #51
dawehnerWe would need to take into account that someone might have moved the link around or renamed it.
Comment #52
wmostrey commented@dawehner The menu item can not be renamed, that's one of the things we're trying to solve here. We do take the item's weight and enabled state into account.
Comment #53
dawehnerIt could have been moved to a different place though.
Comment #54
dqdIs there any issue, I am not aware of, we can relate to from here where this behavior has been caused in the development of Drupal 8 before? In Drupal 7 the only reason for not editable links were reasonably caused by menu links created by views pages (configuration prioirity weight). I think we first should track down where this decision has been made (*facepalm*) and why/where this is coming from, before we override it and wake up with another bad decision surprisingly.
Comment #55
akashkrishnan01 commentedComment #57
mlncn commentedThis issue is about fixing the home link in the standard profile. We should let that fix go in. That said, i'm with those saying we (also) need a general solution for this.
The problem is that module-provided (or install profile provided) menu links cannot have their titles edited, and this is unconscionably annoying. Yet the solution here is to make one link *not* be directly code-defined.
I got here looking for a way to let site administrators edit the name of the menu link that Give module provides. As a maintainer of the module I could simply give people another field in the configuration of the module, but making module-provided menu items have easily overridable, translatable titles is a common need that should have a fix in Drupal core.
Comment #58
romreactor commentedHas this been resolved or altered in Drupal 8 version 4. As I accidentally deleted my initial home page and now am unable to get around this useless home menu link in my Drupal install. I know that best way is to reinstall Drupal, but maybe there we can make it customizable in the future Drupal version this way no patch is required. Would love your insight.
Thanks.
Comment #59
dqd@romreactor: first things first: this issue here is a bug report, and the issue queue as a whole is a community driven issue tracker wtih support from community members (like you and me) and some companies who sponsor core and contrib development in different ways. I know you know that, but the way you ask "if it is solved" indicates that you maybe do not know how it reads what you ask for. Contribute: If you want to know if it is solved but not reported here, you should install a test project, try around with it, read the issue queue, check the latest comments, follow the latest commits and if you find out the rare case that it is solved but not reported here, you should contribute to this issue by commenting here helpful info about your tests and that some reports are missing. Or you can look into the patch in if there is anything you can help with. Many WTF issues are caused by good reasons not easy to work around, as you will find out soon.
Now to your "support request": Reinstalling Drupal is not required in your case. "To get around" your useless menu link, simply deactivate it and make a new one. Custom menu links are more flexible anyway. If your "frontpage" content is missing, check admin/structure/views if there is still a frontpage view. If not, create a new one. This is the power of Drupal. :) Greetings.
Comment #60
mlncn commentedThere's now a patch for the general solution: #2916639 Which is wonderful!
Still in favor of this issue also, and its patch, which simply makes the menu link not 'machine provided' when it doesn't have any reason to be.
Comment #67
damienmckennaShould this be a bug report instead of a task? It's a little silly that the title isn't editable.
Comment #68
scotwith1tI gotta +1 this and love that this has the #DrupalWTF tag. I couldn't believe I was even having to search for such a thing as to why the "Standard module" (whatever that is, since it's really an install profile) won't let me delete this link. OK, sure, most sites have a Home menu link, but not being able to remove or edit it really threw me. Not that disabling it is a difficult or ineffective alternative but really a DrupalWTF moment for me.
Comment #71
er.garg.karanThe patch provided in #2838106-47: Standard profile: make "Home" menu link to <front> editable/deletable doesn't work for Drupal 9.4.
Used it to create a patch for Drupal 9.4
Comment #72
er.garg.karanTaking care of the findings of the failed test findings of #2838106-71: Standard profile: make "Home" menu link to <front> editable/deletable
Comment #74
er.garg.karanTaking care of the findings of the failed test findings of #2838106-72: Standard profile: make "Home" menu link to <front> editable/deletable
Comment #76
xpersonas commented+1 on #DrupalWTF. I can't believe I'm encountering this problem with Drupal 10 in 2023, even if it is a minor issue overall. I either have to hack some code to remove it or tell my clients "just ignore that" because it's an immovable object - no one knows how or why it exists but we know you can't change anything about it!