Problem/Motivation
If the user creates a custom menu link (i.e. a menu link content entity) the original user input is not retained in any way after we resolve it to a route. Thus, the link becomes invalid if the path resolves to another valid route if the original route goes away
For example,
(also see the use cases in the meta issue, "So, if the user types blog, store user-path:blog." under the heading "Menu link storage on the back-end to support these use cases")
before this issue the problem is when you:
make view
in the menu ui, make /blog menu item:
blog
is stored as route views.block.page_1
disable the page display
menu item still stores views.block.page_1
create a panel with path: blog
(it doesn't create a menu)
You expect the link to still work and point to /blog
menu still points to views.block.page_1
and it is broken
Proposed resolution
Store the user input by using a link field. The link field itself just has a UR, (maybe) title and options (may be description) stored.
Follow up: Decide when and how to update or resolve the route - e.g. can make these plugins participate in discovery and resolve the route then. Doing that in #2417423: Re-process the user-entered-paths for custom menu links when there is a menu rebuild
Remaining tasks
- (done) Decide on implementation, do it.
- (done) file follow-up issues
- (done) update issue summary
- (done) change record is drafted
User interface changes
N/A
API changes
Change to base table of entity.
| Comment | File | Size | Author |
|---|---|---|---|
| #61 | link not avaialble.png | 39.63 KB | RavindraSingh |
| #59 | interdiff.2406749.54.59.txt | 754 bytes | yesct |
| #59 | 2406749-59.patch | 27.55 KB | yesct |
| #54 | interdiff.txt | 2.37 KB | amateescu |
| #54 | 2406749-54.patch | 27.52 KB | amateescu |
Comments
Comment #1
webchickOn our branch maintainer call, we decided that since this is a hard-blocker to finalizing the menu links system, this is indeed a critical issue. Tagging.
Comment #2
dawehnerOn the call we agreed that we store the user input itself.
Let's start simple, and store what we put in.
Should we distinct clearly between the external url and the path of the input?
Comment #3
catchI don't think this is actually postponed on anything?
Comment #4
pwolanin commentedIndeed - not postponed - we can start making the new entity or converting the existing on to just take user input.
Comment #5
dawehnerState in HEAD is that you can already, from an API POV store the path in the url part, and store the route name separately, so the simplest imaginable way would be to
store it there and be done.
Comment #6
dawehnerAnother try. Let's not store route name and parameter to see how many failures we get. On the longrun we will switch to the link field here.
Comment #7
dawehnerAnother try. Let's not store route name and parameter to see how many failures we get. On the longrun we will switch to the link field here.
Comment #9
webchickRemoving out-dated child/postponed information from issue summary.
Comment #10
dawehnerI think the proper plan would be following: use a link field. Adapted the issue title and IS for that.
Comment #11
dawehnerSome progress
Comment #13
dawehnerWorking on it
Comment #14
dawehnerLet's see how much is left.
Comment #15
amateescu commentedJust a short observation for now: are you sure this is correct? I would think that 'link_path' needs some processing in order to become a URI.
Comment #17
gábor hojtsyThe link field has a title and a description on it (following #2413029: Change LinkItem schema to also store a description). The menu item link also has a title and a description on it. What is stored in these and how is translation handled? This looks confusing to me.
Comment #18
gábor hojtsyAdd missing tag.
Comment #19
gábor hojtsyThere is a bunch of discussion on #2235457: Use link field for shortcut entity on not using the link field's title and description. I guess that applies here also. However that RTBC patch adds the link field as translatable. Would that make sense here as well?
Comment #20
hussainwebRerolling the patch in #14 after #2235457: Use link field for shortcut entity got in.
Comment #21
wim leers#17: great point. amateescu said in #2235457-3: Use link field for shortcut entity: — by that same reasoning, the menu link entity indeed should not use the link field's
descriptionproperty.But, this is putting words in his mouth — I wonder what amateescu thinks? :)
Comment #22
wim leersAnd related: #2413029-10: Change LinkItem schema to also store a description — the validity/necessity of adding a
descriptionproperty to the link field is now questionable AFAICT.Comment #24
gábor hojtsyIn #19, I incorrectly stated that #2235457: Use link field for shortcut entity had the link field translatable, that is not true. So I guess fine here to not have it translatable either.
Comment #25
amateescu commentedI didn't want to derail #2235457: Use link field for shortcut entity, which was finally ready and had some nice improvements for the link field, so I stayed away from the title debate, but my current thinking is exactly the opposite of what I wrote there almost a year ago :/
Some reasons for this change of heart:
On the other hand, if we decide to use the title property of the link field, I'm afraid we'll have some more work to do in order to support specifying a field property (e.g. link__title) as the 'bundle' key in the entity type annotation, but maybe that's not too much work?
In the end, I'm not really decided on either approach so let's discuss a bit more :)
Comment #26
berdirIf you want to natively suggest field properties for entity keys, which should be easy enough (see ContentEntityBase::getEntityKey()), then I would suggest link.title, because that will just work with $entity_query->condition().
Also, was not aware that you changed your opinion on that topic (well, how could I ;)), so I silently supported the decision to keep title separate in the shortcut issue based on what i remembered from our old discussion there ;)
Comment #27
amateescu commentedI was just about to post exactly this but I refreshed the page and saw your comment :)
Comment #28
dawehnerBeside that it doesn't work for base fields, see #2415001: EntityQuery should be independent from schema for fields.
What I don't like is that once you add the title to the link field, you have potential limits on the way how you built your UI, which is bad. The data modelling should not affect the way how the UI is built and wise versa.
Comment #29
dawehnerWorking on it for now.
Comment #30
xjmComment #31
dawehnerThis will be green!
Comment #32
dawehnerUnassign it for now.
Comment #33
jibranThis url <-> uri thing big DrupalWTF can we have some clarity please.
Shouldn't it be get uri?
so url is uri :S
We can remove this now.
Comment #34
wim leersI'll attempt explaining this.
URI is an identifier, URL is a locator. Roughly: URIs identify some resource, URLs allow you to locate (obtain) some resource.
IOW: we can use URIs internally as long as we translate them to URLs when presented to a browser; a browser doesn't understand
entity:URIs for example.Comment #35
pwolanin commentedLINK_INTERNAL should probably be LINK_GENERIC?
Comment #36
pwolanin commentedSo, we have to be clear that these changes are temporary until we fix the link field to use a URI, but are ok on that basis.
Also, agreed that
getUrl()should begetUrI()ugh - looks in the editor the same but URL to URIComment #37
wim leersInitial review:
This no longer matches the behavior described by the docs:
Returns the external URL if the menu link points to an external URL, otherwise NULL.The path validator should only be used for
user-path:URIs I think?EDIT: d'oh,
user-path:didn't land yet, so this doesn't make sense yet.This looks wrong; this means that also for menu links that link by route will have
urlset in the definition.Wonderful simplification here, if it's correct :)
Nit: Unintended change.
Comment #38
dawehnerJust in case someone wonders: This is caused by #2391217: Support base fields with multiple columns in entity queries
Comment #39
dawehnerAnd here is patch.
Comment #41
wim leersNit: you could pull this out of these ifs and do it in both cases, unconditionally.
Nit: Interesting code formatting :)
This causes a notice at
/admin/structure/menu/manage/tools/add:Notice: Trying to get property of non-object in Drupal\menu_link_content\Form\MenuLinkContentForm->form() (line 223 of core/modules/menu_link_content/src/Form/MenuLinkContentForm.php).This causes a warning upon saving:
Warning: Creating default object from empty value in Drupal\menu_link_content\Form\MenuLinkContentForm->buildEntity() (line 277 of core/modules/menu_link_content/src/Form/MenuLinkContentForm.phpentity:Comment #42
yched commentedThis is somewhat above my head, but looks like an awesome simplification.
I'm a bit surprised at the number of times MenuLinkContentForm ends up calling $this->extractFormValues(), but that's just me looking at code I never saw before, this is not added here :-)
No way to use a link widget instead of some custom $form logic here ? I guess probably not if the patch doesn't do it, but it looks like it hasn't been mentioned in the issue so far, so, just asking :-)
Comment #43
yched commentedYup - could we link to that issue in a @todo so that we can cleanup when that other issue is fixed ?
Is that the same reason/bug here ? @todo as well ?
Comment #44
dawehnerFixed the remaining review points ... and added a follow up for the FIeld
Comment #45
dawehnerWell yeah, we thought that would be easy but it turned out it isn't at all. LinkWidget has additional problems on top of the existing LinkItem had.
Therefore we have an additional issue for that: #2416955: Convert MenuLinkContent to use a link widget
Yeah it is, because ES::loadByProperties uses entity query.
Comment #48
dawehnerLet's get it in.
Comment #50
hussainwebI think you uploaded the README.txt instead of an interdiff. :)
Comment #51
hussainwebRerolling the patch in #48 for conflicts from #2364157: Replace most existing _url calls with Url objects.
@dawehner: I think you uploaded another file by mistake instead of the interdiff. Please upload it if you think it is necessary.
Comment #52
kim.pepperInterdiff of #45 and #48.
Comment #53
dawehnerThis can't be right.
Comment #54
amateescu commentedJust a couple of small fixes. The patch looks ready to me.
Comment #55
yesct commenteddoes the change in #53
the !
mean there is missing test coverage?
Comment #56
yesct commentedwhich issue would this todo be?
Comment #57
yesct commentedguessing this needs change record updates before it is rtbc.
Comment #58
yesct commentedfor #55 -> #2417359: Add test coverage for MenuLinkContentAccessControlHandler::accessCheck() when "We allow access, but only if the link is accessible as well."
for #56
#2411333: Create standard logic to handle a entity: URI scheme is in.
so #2417367: Use the new entity: URI scheme will be that @todo
I'll make a new patch that references that issue.
Comment #59
yesct commentedHere is the patch.
---
Also searched for which change records might need to be updated
"entity base table" returns no results https://www.drupal.org/list-changes/published?keywords_description=entit...
"entity table" https://www.drupal.org/list-changes/published?keywords_description=entit...
returns
Database schema of content entities is automatically generated based on entity type and field definitions https://www.drupal.org/node/2259243
this patch is changing code from previous menulinkNG issues so maybe there is something to change in
Menu links converted to plugins, including static, views, and content entity implementations https://www.drupal.org/node/2302069
still looking for change records.
Comment #60
yesct commentedmaking a new mega change record for issues related to the meta, and putting in details from here into that.
initial guess at title: Configurable link field, short cut, menu links store user entered paths as URI (not routes or paths)
https://www.drupal.org/node/2417421
also updated the issue summary.
Comment #61
RavindraSingh commentedI think the added issue

#2417367: Use entity: in MenuLinkContentAccessControlHandler instead of 'link' => ['uri' => 'node/' . $node->id()], will be that @todo - doesn't require any work. link is not attribute in create entity thats why.
Comment #62
yesct commented@RavindraSingh
Thanks for looking at this.
You are correct, link is not in head right now.
this patch is adding [link] to the array. so that issue will make sense when this gets committed.
----
I read through the patch a couple times, the summary is up to date, the change record draft made, and follow ups created. RTBC from me.
Comment #63
pwolanin commentedComment change in #59 looks fine - I discussed in person with YesCT
Comment #64
jibran+1 for RTBC.
Comment #65
webchickMmm, that's a tasty diffstat! :)
Two questions when reading through. One: What's up with this?
We should be able to do that as of ~20 hours ago, no? However, reading #2417367: Use the new entity: URI scheme it looks like this was deliberately split off because it could be tricky to get tests passing. Fair enough. It's not different from what's in HEAD atm which is also not using entity: so I think this is ok.
Two: What's up with this?
However, this is also covered with a @todo, and #2391217: Support base fields with multiple columns in entity queries seems to cover this case fine.
Everything else looks pretty straight-forward, so going to go ahead and get this in so we can continue to make progress.
Committed and pushed to 8.0.x. Thanks, all!!
Comment #67
yesct commentedfound #2417809: link and shortcut have baseFieldDefinition settings that do not do anything: default_value max_length
came from code copied from shortcut
Comment #68
benjy commentedJust an FYI, this patch updated files in "core/modules/migrate_drupal/src/Tests/Table" which are automatically generated from a database dump but didn't update the database dump.
This has been fixed in #2410623: D6-D8 Custom Block Migration not visible in region
Comment #70
sutharsan commentedI have written the unit tests in #2417359: Add test coverage for MenuLinkContentAccessControlHandler::accessCheck() when "We allow access, but only if the link is accessible as well." as requested in #58. I would appreciate a review to see whether it covers the case(s) affected by this issues.