Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The original menu link UI looks like this:
A patch in #2406749: Use a link field for custom menu link was committed to move this to a standard link field, and results in a UI like this:
Regressions:
- Field is now called "URL" rather than "Link path." Yet you very rarely actually type URLs here, so the label is incorrect.
- It's now surrounded by an extraneous fieldset with a redundant title of "Link"
- It ends with a grammatically incorrect sentence floating in space.
Proposed resolution
Undo all of that.
Remaining tasks
Review / test the patch.
User interface changes
Yes.
API changes
I'd hope not.
Comment | File | Size | Author |
---|---|---|---|
#69 | 2416987.69.revert-2416987-56.patch | 1.25 KB | YesCT |
#61 | 2416987-followup.patch | 711 bytes | amateescu |
#57 | Screen Shot 2015-02-02 at 12.22.55.png | 81.49 KB | Wim Leers |
#57 | Screen Shot 2015-02-02 at 12.22.38.png | 77.15 KB | Wim Leers |
#56 | interdiff.txt | 799 bytes | amateescu |
Comments
Comment #1
webchickA few small clean-ups.
Comment #2
catch#2407913: Discuss/define the minimal UX for adding menu links to entities got resolved.
Comment #3
Wim LeersI'm taking this on now.
Comment #4
amateescu CreditAttribution: amateescu commentedIsn't this blocked on #1959806: Provide a generic 'entity_autocomplete' Form API element?
Comment #5
Wim Leers#4: it isn't, because the initial version of this will not have the autocomplete yet. Or, at least, the initial patch won't use it, it will only implement the desired validation logic and will require the
user-path:
andentity:
schemes to be used. In a follow-up issue, we can then just add the autocomplete support on top of that. This allows us to keep moving forward :)Comment #6
amateescu CreditAttribution: amateescu commentedOh, nice plan :) Only now I saw the "basic UI" part in the issue title...
Comment #7
YesCT CreditAttribution: YesCT commented#2416955: Convert MenuLinkContent to use a link widget landed, should help with this.
Comment #8
YesCT CreditAttribution: YesCT commented@Wim Leers switched to another issue, I'm going to take a stab at this.
Comment #9
YesCT CreditAttribution: YesCT commentedwe can hack at making a new widget, but using it is blocked on #2417793: Allow entity: URIs to be entered in link fields (via conversation with @Wim Leers)
Comment #10
YesCT CreditAttribution: YesCT commentedComment #11
YesCT CreditAttribution: YesCT commentedcopied LinkWidget,
made a MenuLinkWidget (can change name later) (can move the location of the class later to whereever later, menu link content?)
Changed the name of the path input field to Link
And removed the fieldset.
Comment #12
YesCT CreditAttribution: YesCT commentedMenuLinkContent
BaseFieldDefinition for link
sets title to disabled,
but we will never want to use the link title since we have a Menu link title.
Comment #13
amateescu CreditAttribution: amateescu commentedI thought the whole point of writing a generic link widget was to use it everywhere (link field, shortcuts, menu links)?
Comment #14
yched CreditAttribution: yched commentedYup, a bit sad to duplicate the widget just to get rid of the fieldset.
Couldn't the widget determine that if there's only a 'link' input to display, the fieldset is not needed ?
Comment #15
amateescu CreditAttribution: amateescu commented+1 to #14.
Comment #16
YesCT CreditAttribution: YesCT commentedyep. it is weird. but I'm just playing for now.
also, here is the diff between the two widgets, more useful than the first patch which is a copy and changes.
Comment #17
YesCT CreditAttribution: YesCT commentedRemoving the fieldset removes the
The location this menu link points to.
help text.
Also, I know why the description is at the end, because it is the description for the whole link thing
not the description for the uri form element (input field), that is: This can be an internal Drupal path such as node/add or an external URL such as http://drupal.org. Enter to link to the front page..
Related #2396145: Option #description_display for form element fieldset is not changing anything
--
I'll try next changing the LinkWidget.
Comment #18
YesCT CreditAttribution: YesCT commentedthis is a hack. just taking notes.
If we get rid of the fieldset description (and use a better label)
then we dont need to worry about how to have the fieldset description helptext but no fieldset decoration.
Comment #19
YesCT CreditAttribution: YesCT commentedno interdiff cause this is a different approach.
some code from tim plunkett. They had the idea of making it more general than trying to see if was a menu link and ... but I have a concern.
will explain in next. comment.
Comment #20
YesCT CreditAttribution: YesCT commentedthis comment came from issue #1957670: Link field labels don't show in entity forms but it was not clear why it was only when cardinality == 1. I made the comment more accurate when I changed it anyway to explain the new additional condition on adding the fieldset.
(I know, ironic given the issue we just did before which took it out and then put it back in)
we can get rid of the description, if we make the label better.
This allows use to do a trick with not having to show the description even when we do not want the fieldset. (the description goes away when we take the fieldset off).
BUT the problem is, when we take the fieldset off, we get the label from the uri form element (not the link field).....
and I made a link field on page content type, diasabled the title ... and I lost my field label and the description I carefully crafted...
so this has to be more specific to menu... or not from a field UI something. :(
and if we change the uri field element label... it changes that everwhere, not just for menu links.
[edit: shortcut uses the same, so needs to work for that also. note that on the shortcut form, ( admin/config/user-interface/shortcut/manage/default/add-link ) Note shortcut doesn't have the uri form element help text because it is 'link_type' => LinkItemInterface::LINK_INTERNAL, ]
Comment #21
YesCT CreditAttribution: YesCT commentedmoving to needs review to let the tests run on the patches.
Also... this is ready for someone to look at. I'm done just "playing", and think this is worth considering.
If testing manually, keep in mind you will want to try all the things that use link, since this changes link widget (not just menu links).
Screenshots coming.
Comment #23
Bojhan CreditAttribution: Bojhan commentedI am following this, but why are we reviewing a UI where the main interaction is still missing? I was assuming this was a in between step?
Comment #24
YesCT CreditAttribution: YesCT commentedMenu link
admin/structure/menu/manage/main/add
Shortcut
admin/config/user-interface/shortcut/manage/default/add-link
link in content type with cardinality > 1
title optional
title disabled
Comment #25
YesCT CreditAttribution: YesCT commentedcardinality > 1 title disabled
:(
field help text, is both on the whole filed and on each uri form element
Comment #26
YesCT CreditAttribution: YesCT commentedI'm going to dinner.
Comment #27
YesCT CreditAttribution: YesCT commentedjust a reroll. automatic 3 way merge
Comment #28
YesCT CreditAttribution: YesCT commentedthis needs a review.
we can do the autocomplete in #2418017: Implement autocomplete UI for the link widget
Comment #29
YesCT CreditAttribution: YesCT commentedfix for #25
Comment #31
YesCT CreditAttribution: YesCT commentedoops. this is the patch
Comment #32
webchickHm. Not that this isn't worth doing, but this is not remotely a critical problem anymore if that's the scope.
Comment #33
YesCT CreditAttribution: YesCT commentedI agree.
Comment #34
webchickRedid the issue summary since the old one no longer makes sense. I'm a bit confused why this issue was transformed in such a dramatic way vs. just opening a new issue, but nevertheless...
Comment #35
jibranWe should file a bug for this issue. When a widget has more then one field we have to make a special rule for cardinality 1. See #2331331: Widget for cardinality 1 is missing the field label
Comment #36
webchickOk, now the review! :)
So first off, thanks so much for the thorough run-down of before/after comparisons in #24. Would never have thought to try that many permutations! And the "after" screenshots look really good.
I'm a bit concerned though about the amount of special-casing it takes in the patch to achieve this, using settings that are apparently unique to LinkWidget, since I don't see any other widgets in a cursory glance with a "title" setting. In my naïve mind, making all of these interfaces re-use the Link widget would've looked something like this:
So my counter-proposal would be:
- Rename the URL field to "Link"
- Flip the order of Link title and Link, since it's an OK assumption that everywhere you ask for a link it makes sense to ask for its "human-readable" name first.
- Instead of Shortcut, Menu, and whatever else having their own "Name" field, use the Link field's "Link title" instead.
- Only put a fieldset around the thing if there are > 1 values.
- Only write the help text once, at the bottom.
- Then, have all of those places just use a link field, un-special-cased.
But obviously, if your patch is what yched/amateescu had in mind, that's fine.
Comment #37
YesCT CreditAttribution: YesCT commentedI'm also not totally sure what to do here.
Note, that for menu links, and shortcuts, the title is NOT part of the link field. (but we can make the UI without worrying about that implementation detail)
in #36
for the generic link widget,
it switches the order of the uri and the link title, so that it looks like the order for menulinks and shortcuts. (could be a good idea, but different from d7 (and d8 so far) for anywhere the link field is used. can we go back and see if the order was chosen for a reason originally?)
There is help text (or there could be) for the field and also for each form element... and that is not in the sketches in #36
And #36 is missing the case where the title form element is disabled. ... maybe we want to not design for that?
In the sketch in #36, for single value link, looks like there is some styling to group the link title and link... so that would be fieldset with a box.
oh, and I just noticed in #25 that the field label was used for each link element label ... need to try patch 29 and look closer to see what that looked like for that case.
hmm. (also, hm... tests for the UI maybe need to be added for whatever we decide it should be like, sounds like a lot of simple test and xpath)
I'll try some of the suggestions in #36. (feedback welcome still on variations, so leaving at needs review)
Comment #38
dawehner... I do agree for menu links and shortcuts title first totally makes sense, its required ...
for a normal link field I disagree ... why should a optional title comes first? Semantically a link is primarily a URI and then also has a title.
Comment #39
Wim LeersWould it perhaps make sense to create a "URL-only link widget", for use on entities where a link field is used as a base field, but only to store URIs?
That'd allow us to easily optimize for that use case, of which we now have 2 instances (Shortcut and MenuLinkContent), but still reuse most logic.
Comment #40
YesCT CreditAttribution: YesCT commented@Wim Leers Yes it would be good to see what that solution looks like.
For now, just fixing something in the previous approach. (title when cardinality != 1 was replacing the url form element label with the field label, so it was repeated a bunch)
did a $cardinality_is_one since call to getFieldStorageDefinition() was needed in a bunch of places
now:
Comment #41
YesCT CreditAttribution: YesCT commentedsomething a little strange,
if I fill out something in the form element for the link text, but do not fill out anything for the url form element, then the whole form saves ok without an error or warning... and does not save the words I put in the link text form element. (url is not conditionally required when the link text is filled out, but the whole field is optional).
Comment #42
YesCT CreditAttribution: YesCT commentedthis interdiff does 2 things,
adds keeps URL when sucking in the parent field label as the label for the uri form element. It does this by using (URL) at the end of the label.
the other thing it does is make the title/name and page title more consistent between menu link and shortcut
noticed something wrong, no help text when either internal only or external only. :( I'll add that in.
(if we go this direction, the issue title probably becomes: make UI consistant (which fixes regression for menu links) )
I will try a widget that doesn't mess with the generic link widget though... in a bit.
Comment #43
YesCT CreditAttribution: YesCT commentedah, when internal only, the field is prepended with the url of the site. so no helptext is needed.
wait, you can use ... maybe we should say that. no. people wont want to use link to link to the front page. nvm.
this adds the help text, rearranges a little code to flow better.
interdiff.43a.txt is not in the patch, (but would apply on top of patch 43). it makes less code, but I wonder if it is less clear, or more prone to break later.
something not really related, but I noticed, is that we should probably use http://example.com as the example of an external url, not drupal.org (or make it configurable). <- separate issue to search for user facing strings and replace them. (workaround is form alter)
-------
screenshots as of 43.
-----
I'm going to take a break from this.
Me, or someone next should try, alternative approach, see #39.
Comment #44
webchickReally sorry, I did not mean to derail this issue. I think all we need here is just "fix the UX so it doesn't look so silly" (resolve the problems in the issue summary) ... we can discuss awesomer ways to do that in follow-up issues. I was just a bit surprised that the patch looked the way it did, as it was more complex than I expected given the work to unify these UIs.
Not sure who exactly to assign this to, since Link module has "?" as a maintainer, but feels like we need an architectural direction here. But since amateescu has been pushing hardest for this approach, assigning to him for feedback.
Comment #45
amateescu CreditAttribution: amateescu commentedThe problems outlined in the issue summary seem to be quite easily solvable.
The change is basically this: when the field cardinality is 1 and the link text is disabled, don't display any fieldset and use the field label as a title for the 'uri' field property.
Here's how it looks like after I changed the label of the 'link' field on MenuLinkContet to link path:
Comment #46
Wim LeersOh, right, this doesn't set
#tree => TRUE
, hence this doesn't break any of the form handling. Awesome! :)IMO "link path" is wrong; it isn't always a path, especially not when it contains a
entity:
URI (or an external URL). Technically, it should be "URI", but that's not very user-friendly, so probably keeping "Link" is best. IMHO.Comment #47
davidhernandezI noticed that in shortcut and menu the link text is always above the url box, but for Link fields it is below. Is that an inconsistency that needs to be addressed?
Comment #48
amateescu CreditAttribution: amateescu commentedThis will get even more complicated in #2418017: Implement autocomplete UI for the link widget, so I just used "Link path" for now to have 1:1 parity with the old UI. But I'm not opposed to changing it if others feel the same as you.
Comment #49
webchickYeah I think I'll remove that hunk. I agree "Link" is best.
Any other comments or can we get this sucker in? :)
Comment #50
webchickOh and regarding #47, yes that inconsistency is ok. As dawehner pointed out in #38, in the other cases (menu link UI, shortcut) the title is a required field so makes sense to come first, but in the case of link fields the title is optional; if it's omitted it'll just display https://drupal.org/ which is fine.
[Edited to make some kind of sense. :P]
Comment #51
catchI'm confused by this issue.
From the title it looks like it's discussing the form_alter on nodes that allows you to create a menu link from there.
But looks like it's actually about the link field widget on entity forms?
Comment #52
amateescu CreditAttribution: amateescu commented#51 is right, I was also confused by the title after reading the issue summary.
Comment #53
amateescu CreditAttribution: amateescu commentedSloppy me.
Comment #55
yched CreditAttribution: yched commentedIf it's fine functionally, latest patch seems right to me.
Nitpicks:
Missing trailing point
$element['#title'] comes prepopulated with the correct title (field label), we could also re-use it from there. No biggie.
Comment #56
amateescu CreditAttribution: amateescu commentedI need to learn more of this Field API thingie, it's kinda awesome.
Edit: And the trailing dot was fixed in the previous patch :)
Comment #57
Wim LeersWorks perfectly.
(First file is before, second is after.)
Comment #58
webchickGreat!
Committed and pushed to 8.0.x. Thanks!
Comment #60
YesCT CreditAttribution: YesCT commentedI dont think this solution was tried with all the permutations and combinations.
For a Link field on a content type, with cardinality 1, and the link text disabled, the helptext for the field is gone.
So now this is a regression in the link field UI.
Comment #61
amateescu CreditAttribution: amateescu commented@YesCT, that's correct, I only tested the link field on the menu link form and one added to nodes through field UI, neither of which had any description :/
We have two options here, either add it to
$element['uri']
as a #suffix or append it directly to #description. Here's a patch for the first option which should be more clear.Comment #62
jibranAs per #60
Comment #65
jibranWe also need test for
.Comment #67
catchPlease open a new issue for the patch from #61 and the test coverage. Multiple patch issues get confusing in git history.
Comment #68
yched CreditAttribution: yched commentedre #61 : I might be wrong, but aren't there some tricky subtleties about auto-escape with special cases on #description ? Not sure if putting the description text in #suffix would trigger the expected escaping behavior
Comment #69
YesCT CreditAttribution: YesCT commentedI change my mind.
Let's revert this.
Then, add test coverage and fix it without adding a worse regression.
This regression fixed style on the menu link form. but caused missing help text on other forms. That seems worse.
patch is to see if it still passes with the revert.
I did
git revert bef6c3beee9080585f75ed1ea89f6650f4494a51
on a new branch and then diffed against 8.0.x to get the patch
then we can put it back to normal.
Comment #70
Gábor HojtsyLet's do what @catch suggested in #61.
Comment #71
YesCT CreditAttribution: YesCT commentedthis was a normal when it was committed.
#2421001: Fix regression in the link widget where help text does not show
Comment #72
YesCT CreditAttribution: YesCT commented#2421011: Make shortcut add and edit form titles better
is for the shortcut consistancy changes.
Comment #73
YesCT CreditAttribution: YesCT commented#2421021: Missing help text for external url only for link widget
is for another bit that was in #43
Comment #74
jibranThis was also a task.