Problem/Motivation

The original menu link UI looks like this:
Simple text field stores a user-entered path.

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:

Link field now called URL, in a fieldset

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.

CommentFileSizeAuthor
#69 2416987.69.revert-2416987-56.patch1.25 KBYesCT
#61 2416987-followup.patch711 bytesamateescu
#57 Screen Shot 2015-02-02 at 12.22.55.png81.49 KBWim Leers
#57 Screen Shot 2015-02-02 at 12.22.38.png77.15 KBWim Leers
#56 interdiff.txt799 bytesamateescu
#56 2416987-56.patch1.25 KBamateescu
#53 interdiff.txt852 bytesamateescu
#53 2416987-53.patch1.26 KBamateescu
#52 interdiff.txt700 bytesamateescu
#52 2416987-52.patch1.26 KBamateescu
#45 edit-menu-link-new.png29.92 KBamateescu
#45 2416987.patch1.95 KBamateescu
#43 43-card1-textdesabled.png149.68 KBYesCT
#43 43-card1-textoptional-externalonly.png141.23 KBYesCT
#43 43-card3-textdisabled-internandextern.png192.81 KBYesCT
#43 43-cardN-textopt-internalonly.png152.35 KBYesCT
#43 43-shortcut.png137.38 KBYesCT
#43 43-menu.png150.92 KBYesCT
#42 42-nohelptext.png203.16 KBYesCT
#42 42-shortcutconsistancies.png195.87 KBYesCT
#42 42-menulabels.png186.52 KBYesCT
#40 40.better.png205.09 KBYesCT
#40 29-grr.png228.19 KBYesCT
#36 Screen Shot 2015-01-31 at 10.57.31 PM.png39.12 KBwebchick
#34 Screen Shot 2015-01-31 at 10.08.58 PM.png37.18 KBwebchick
#31 2416987.29.patch5.62 KBYesCT
#29 interdiff.2416987.27.29.txt999 bytesYesCT
#29 2416987.29.patch999 bytesYesCT
#27 2416987.27.patch5.51 KBYesCT
#25 21-oops.png403.1 KBYesCT
#24 21-linkpage2.png349.92 KBYesCT
#24 21-pagelinksame1.png297.55 KBYesCT
#24 21-linkoncontent.png428.76 KBYesCT
#24 21-shortcut.png324.98 KBYesCT
#24 21-menulink.png349.47 KBYesCT
#21 interdiff.2416987.19.21.txt3.24 KBYesCT
#21 2416987.21.patch5.48 KBYesCT
#20 pagelinkfield.png198.38 KBYesCT
#19 2416987.19.patch3.14 KBYesCT
#18 hacksimplified.png423.79 KBYesCT
#18 2416987.18.do-not-test.patch1.88 KBYesCT
#16 interdiff.LinkWidget.MenuLinkWidget.txt1.55 KBYesCT
#12 interdiff.2416987.11.12.txt1.58 KBYesCT
#12 2416987.12.patch9.39 KBYesCT
#11 2416987.11.patch2.51 KBYesCT
Screen Shot 2015-01-29 at 8.35.56 PM.png24.2 KBwebchick
Screen Shot 2015-01-29 at 8.19.41 PM.png24.6 KBwebchick
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

webchick’s picture

Issue summary: View changes
Issue tags: +Usability

A few small clean-ups.

catch’s picture

Wim Leers’s picture

Assigned: Unassigned » Wim Leers

I'm taking this on now.

amateescu’s picture

Wim Leers’s picture

#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: and entity: 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 :)

amateescu’s picture

Oh, nice plan :) Only now I saw the "basic UI" part in the issue title...

YesCT’s picture

YesCT’s picture

Assigned: Wim Leers » YesCT

@Wim Leers switched to another issue, I'm going to take a stab at this.

YesCT’s picture

Status: Active » Postponed

we 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)

YesCT’s picture

Issue summary: View changes
YesCT’s picture

FileSize
2.51 KB

copied 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.

YesCT’s picture

MenuLinkContent
BaseFieldDefinition for link
sets title to disabled,

        'title' => DRUPAL_DISABLED,

but we will never want to use the link title since we have a Menu link title.

amateescu’s picture

made a MenuLinkWidget (can change name later) (can move the location of the class later to whereever later, menu link content?)

I thought the whole point of writing a generic link widget was to use it everywhere (link field, shortcuts, menu links)?

yched’s picture

Yup, 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 ?

amateescu’s picture

+1 to #14.

YesCT’s picture

yep. 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.

YesCT’s picture

Removing 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.

YesCT’s picture

this 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.

hack simplified screenshot

YesCT’s picture

FileSize
3.14 KB

no 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.

YesCT’s picture

FileSize
198.38 KB
  1. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -121,9 +122,15 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    -    // If cardinality is 1, ensure a label is output for the field by wrapping it
    -    // in a details element.
    -    if ($this->fieldDefinition->getFieldStorageDefinition()->getCardinality() == 1) {
    

    this 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.

  2. +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
    @@ -282,8 +282,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    -      ->setLabel(t('Link'))
    -      ->setDescription(t('The location this menu link points to.'))
    +      ->setLabel(t('Menu link location'))
    

    (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, ]

YesCT’s picture

Status: Postponed » Needs review
FileSize
5.48 KB
3.24 KB

moving 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.

Status: Needs review » Needs work

The last submitted patch, 21: 2416987.21.patch, failed testing.

Bojhan’s picture

I 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?

YesCT’s picture

FileSize
349.47 KB
324.98 KB
428.76 KB
297.55 KB
349.92 KB

Menu 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

YesCT’s picture

FileSize
403.1 KB

cardinality > 1 title disabled

:(
field help text, is both on the whole filed and on each uri form element

YesCT’s picture

Assigned: YesCT » Unassigned

I'm going to dinner.

YesCT’s picture

Status: Needs work » Needs review
FileSize
5.51 KB

just a reroll. automatic 3 way merge

YesCT’s picture

Title: Implement basic UI for adding menu links to entities » Fix regression in UI for adding menu links to entities

this needs a review.

we can do the autocomplete in #2418017: Implement autocomplete UI for the link widget

YesCT’s picture

FileSize
999 bytes
999 bytes

fix for #25

Status: Needs review » Needs work

The last submitted patch, 29: 2416987.29.patch, failed testing.

YesCT’s picture

Status: Needs work » Needs review
FileSize
5.62 KB

oops. this is the patch

webchick’s picture

Priority: Critical » Normal

Hm. Not that this isn't worth doing, but this is not remotely a critical problem anymore if that's the scope.

YesCT’s picture

I agree.

webchick’s picture

Redid 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...

jibran’s picture

+++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
@@ -121,9 +144,15 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
+    if ($this->fieldDefinition->getFieldStorageDefinition()->getCardinality() == 1 && $title_is_enabled) {

We 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

webchick’s picture

Ok, 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:

Four sets of link title / link pairings, the one with multilvalues in fieldset

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.

YesCT’s picture

I'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)

dawehner’s picture

... 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.

Wim Leers’s picture

Would 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.

YesCT’s picture

FileSize
228.19 KB
205.09 KB

@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:

YesCT’s picture

something 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).

YesCT’s picture

this 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.

YesCT’s picture

ah, 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.

webchick’s picture

Assigned: Unassigned » amateescu

Really 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.

amateescu’s picture

FileSize
1.95 KB
29.92 KB

The 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:

Wim Leers’s picture

  1. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -169,12 +169,19 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +      // Otherwise wrap everything in a details element.
    +      else {
    +        $element += array(
    +          '#type' => 'fieldset',
    +        );
    +      }
    

    Oh, right, this doesn't set #tree => TRUE, hence this doesn't break any of the form handling. Awesome! :)

  2. +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
    @@ -280,7 +280,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    -      ->setLabel(t('Link'))
    +      ->setLabel(t('Link path'))
    

    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.

davidhernandez’s picture

I 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?

amateescu’s picture

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.

This 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.

webchick’s picture

Yeah I think I'll remove that hunk. I agree "Link" is best.

Any other comments or can we get this sucker in? :)

webchick’s picture

Oh 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]

catch’s picture

I'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?

amateescu’s picture

Title: Fix regression in UI for adding menu links to entities » Fix UI regression in the menu link form
Assigned: amateescu » Unassigned
FileSize
1.26 KB
700 bytes

#51 is right, I was also confused by the title after reading the issue summary.

amateescu’s picture

FileSize
1.26 KB
852 bytes

Sloppy me.

The last submitted patch, 52: 2416987-52.patch, failed testing.

yched’s picture

If it's fine functionally, latest patch seems right to me.

Nitpicks:

  1. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -169,12 +169,19 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +    // If cardinality is 1, ensure a proper label is output for the field
    

    Missing trailing point

  2. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -169,12 +169,19 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +      // If the link title is disabled, use the field definition label as the
    +      // title of the 'uri' element.
    +      if ($this->getFieldSetting('title') == DRUPAL_DISABLED) {
    +        $element['uri']['#title'] = $this->fieldDefinition->getLabel();
    

    $element['#title'] comes prepopulated with the correct title (field label), we could also re-use it from there. No biggie.

amateescu’s picture

FileSize
1.25 KB
799 bytes

$element['#title'] comes prepopulated with the correct title (field label), we could also re-use it from there. No biggie.

I need to learn more of this Field API thingie, it's kinda awesome.

Edit: And the trailing dot was fixed in the previous patch :)

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
77.15 KB
81.49 KB

Works perfectly.

(First file is before, second is after.)

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Great!

Committed and pushed to 8.0.x. Thanks!

  • webchick committed bef6c3b on 8.0.x
    Issue #2416987 by YesCT, amateescu, webchick, Wim Leers, yched: Fix UI...
YesCT’s picture

I 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.

amateescu’s picture

FileSize
711 bytes

@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.

jibran’s picture

Category: Task » Bug report
Priority: Normal » Major
Status: Fixed » Needs review

As per #60

The last submitted patch, 11: 2416987.11.patch, failed testing.

The last submitted patch, 19: 2416987.19.patch, failed testing.

jibran’s picture

Issue tags: +Need tests

We also need test for For a Link field on a content type, with cardinality 1, and the link text disabled, the helptext for the field is gone..

The last submitted patch, 12: 2416987.12.patch, failed testing.

catch’s picture

Status: Needs review » Needs work

Please open a new issue for the patch from #61 and the test coverage. Multiple patch issues get confusing in git history.

yched’s picture

re #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

YesCT’s picture

Status: Needs work » Needs review
FileSize
1.25 KB

I 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.

Gábor Hojtsy’s picture

Status: Needs review » Fixed

Let's do what @catch suggested in #61.

YesCT’s picture

Priority: Major » Normal
YesCT’s picture

#2421011: Make shortcut add and edit form titles better
is for the shortcut consistancy changes.

YesCT’s picture

jibran’s picture

Category: Bug report » Task
Issue tags: -Need tests

This was also a task.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.