Problem/Motivation
#2416987: Fix UI regression in the menu link form fixed a regression so that the UI was back to a simpler one.
Parts of this are blocked on #2417793: Allow entity: URIs to be entered in link fields
See #2407505: [meta] Finalize the menu links (and other user-entered paths) system and #2407913: Discuss/define the minimal UX for adding menu links to entities for the full backstory.
Basically, in order to ship Drupal 8, we need to restore the ability to form a "smart" link to a piece of content like node/1 that doesn't break even if its path changes, such as from "about" to "about-us." In Drupal 7, this was default behaviour. While we're at it, let's fix a long-standing UX problem due to the fact that normal humans do not know what a "path" is:
Proposed resolution
Based on the decision at #2407913: Discuss/define the minimal UX for adding menu links to entities, implement the UI outlined there. (Note: Exact label/help text hasn't been bike-shedded yet, but we can start on implementation of the behind-the-scenes stuff.)
Behaviour:
- As user types, autocomplete the input against node titles. (A later improvement in 8.0.x or 8.1.x+ could be expanding this UI to allow for other entity types as well, but that's not in scope for this issue.)
- If the input has a slash "/" in it, no longer attempt to autocomplete; instead store what the user typed.
- Code-wise, figure out if what's input is an
entity:node/1
, abase:README.txt
, or auser-path:blog
, or just plainhttp://whatever
, and store in the link field'suri
field accordingly.
Remaining tasks
Blocker: #1959806: Provide a generic 'entity_autocomplete' Form API element- Blocker: #2417647: Add leading slash to paths within 'user-path:' URIs, to allow 'user-path:' URIs to point to the <none> route (see #65 for an explanation why)
- Review code
- Review usability
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#129 | 2019-10-25 17_23_38-Window.png | 21.37 KB | bharat.kelotra |
#119 | 2418017-119.patch | 29.58 KB | hussainweb |
#119 | interdiff-117-119.txt | 597 bytes | hussainweb |
#117 | 2418017-117.patch | 29.59 KB | Wim Leers |
#24 | interdiff.2418017.22.24.txt | 1.49 KB | YesCT |
Comments
Comment #1
YesCT CreditAttribution: YesCT commentedComment #2
webchickOk, #2417793: Allow entity: URIs to be entered in link fields is in, I think this is good to go again.
Comment #3
webchickAlso, fixing some metadata, since this is now the new critical issue for implementing the UX.
It's unclear to me whether #1959806: Provide a generic 'entity_autocomplete' Form API element is a hard or soft blocker for this one. Maybe you folks can discuss tomorrow?
Comment #4
dawehnerWe (yesct, dawehner) are working on providing a minimal implementation of that based upon #1959806: Provide a generic 'entity_autocomplete' Form API element
Comment #5
amateescu CreditAttribution: amateescu commentedThis part of the current issue summary:
is missing a essential part from my proposal: The input *has* to start with a slash "/" in order to be considered a path, because entity titles can contain slashes.
Comment #6
webchickWell, no, because "https://drupal.org/" but fair enough.
Comment #7
amateescu CreditAttribution: amateescu commented@webchick, I was talking about paths as in internal paths, not external URLs :)
Comment #8
dawehneruploading WIP
Comment #9
webchickYayyyy!
Comment #10
amateescu CreditAttribution: amateescu commentedJust a note for the peanut gallery, the size of the patch from #8 is so big because it also includes the patch from #1959806: Provide a generic 'entity_autocomplete' Form API element :)
Comment #12
dawehnerMeh.
Comment #14
dawehnerReroll.
Comment #15
dawehnerHere is a reviewable bit.
Comment #17
YesCT CreditAttribution: YesCT commentedfinding the match, match was 0 from the uid 0, but the if was evaluating that to be false a match was not found.
just the fix for that fail.
[edit: hm. didn't make the review patch correctly]
Comment #19
dawehnerThis could really fix a couple of the failures.
Comment #20
dawehner.
Comment #22
dawehnerA bit of work on some tests in the meantime.
Comment #24
YesCT CreditAttribution: YesCT commentedbread crumb fatals, needed to add / to some things.
Comment #25
jibranHere is original patch without #1959806: Provide a generic 'entity_autocomplete' Form API element for review.
Comment #27
YesCT CreditAttribution: YesCT commentedwe will need to rebase against that.
I did the same thing and applied the latest patch from that issue to a branch. and diffed against this patch on a branch,
but dawehner did not keep up with the fixes there... so we would have to diff against an older patch on that issue (or rebase something)
I think the patch on this issue (the real changes) are smaller.
Comment #28
jibrangit merge to the rescue.
Comment #29
jibranHere is rebased original patch.
Comment #32
YesCT CreditAttribution: YesCT commented?: ternary cannot have a conditional in the front.
and undoing an addition of / before ? (/? means something different than ?)
Comment #34
webchickDoing a UI review atm, here are some screenshots. (Note that yes, the fieldset looks wonky; that's being cleaned up in #2416987: Fix UI regression in the menu link form). Overall this looks pretty thorough:
When you first get to the page it looks like this:
There's an autocomplete spinner but nothing in the help text to explain what the spinner is going to autocomplete. Don't think we can let this in without adjusting that, since we want it to ideally be the 90% interaction.
In terms of the "simplest thing that could possibly work," let's go with "Enter the title of a piece of content, an internal...." (i.e. keep the rest as-is; we can always further refine it in normal follow-up issues.)
As you start typing characters you get an autocomplete of node titles:
The CSS styling looks a bit weird here, since there's no border? Not a commit-blocker, but maybe something to check out to see if there's a typo or something causing styles not to be applied.
Once you select one you get a typical Entity Reference value:
The mock shows also exposing the path here but I think that this is fine. I was mostly spitballing anyway, and arguably exposing the path would encourage people to type paths instead, which we tend to want to discourage them from doing.
Prefixing a path with "/" also works as expected:
There's also validation if you try and type crap in here, with instructions on how to correct it:
The error message could use some tweaking, since most often when they get this it'll be in the service of trying to select content. Maybe something like:
"Content with the title '%title' was not found. If you meant to link to a path, note that paths must start with /, #, or ?." (note the judicious use of Oxford comma! ;))
Side-note: It's _very_ rare to link to a # or a ? compared to a /. I actually think we shouldn't bother exposing those in the error message. They're quite advanced concepts that only people fluent in HTML would know (remember this screen is often for content authors). I could see us setting up a handbook page somewhere that talks about all the crazy things you can type in here and linking to it in a follow-up.
--
Overall, this is looking really good! Excited how fast this came together.
Comment #35
YesCT CreditAttribution: YesCT commentedComment #37
idebr CreditAttribution: idebr commentedRe: webchick in #34:
I noticed this earlier and posted a patch at #2417705: Autocomplete suggestions visual regression after modal and jQuery UI update
Comment #38
idebr CreditAttribution: idebr commentedComment #39
anavarreJust FTR there's a module doing this on D6/D7 but in the context of CKEditor only. Would potentially be good to look at it for inspiration and/or for a follow-up issue to add autocomplete for links added via CKEditor.
Comment #40
YesCT CreditAttribution: YesCT commentedThings to think about in regards to trying to match what they type, and not assuming it was meant to start with / ? # if autocomplete didn't return anything:
on save, if there is an exact title match, and only one match, we could guess that is what they wanted
but if there is more than one title match, we should not pick one.
if we did this the error could be different than suggested in #34
instead of
maybe:
Title '%title' matched more than one piece of content. You might need to use a more specific identifier like entity:/node/1. If you meant to link to a path, note that paths must start with /, #, or ?.
wait... we could tell if it matched more than one, or none. so could give a relevant error. and still use the suggestion.
Content with the title '%title' was not found. If you meant to link to a path, note that paths must start with /, #, or ?.
----
we do not tell the the syntax they can use for all the different ways, maybe link off to a help page?
---
I would prefer to add the search (again) on save (if it didn't autocomplete) in a follow-up. Maybe a normal?
Comment #41
YesCT CreditAttribution: YesCT commented@dawehner suggested that some of this logic be put in a static protected, in the test subclass make it public so you can test it.
This makes the logic cleaner, and simplifies the path through the code for aka /
this wont apply. but uploading it anyway.
Comment #43
YesCT CreditAttribution: YesCT commentedthere was a conflict with a boolean being added to yml trying to go in the same place. put it in and the hunk from this.
Comment #44
YesCT CreditAttribution: YesCT commentedThis might be it!
Comment #46
hass CreditAttribution: hass commentedI'd like to mention that I'm using such a module in D7. We had lot of usability issues as it often lists duplicate articles titles and taxonomy terms with same title. Users have selected wrong links and have not understood why two/3/4 of same title have been listed.
How do you like to solve this UX?
Comment #47
webchickThat was the point of showing the path in the drop-down. However, doing that is going to be in a follow-up, if we decide to do it.
Comment #48
hass CreditAttribution: hass commentedI like this feature a lot and it is a huge usability enhancement to Drupal. We only need to make sure that not only the title is shown and I hope we do not miss to get this in, too. Critical is the proper prio for sure :-)
We also need this in CKEditor... this is where my users using this auto complete a lot.
Comment #49
Wim LeersStraight reroll on top of #1959806-51: Provide a generic 'entity_autocomplete' Form API element (which is RTBC!).
Now fixing the test failures.
(The do-not-test part, which is the actual patch in this issue, is *identical* to that in #44.)
Comment #50
Wim Leers#48: fully agreed! #2292159: EditorLinkDialog should validate URLs, and autocomplete like the Link widget already exists for that.
Comment #52
dawehnerWithout a reroll against the recent entity_autocomplete patch, but with proper fixes.
Comment #53
Wim LeersThe massive number of failures in #49 stems from the fact that #44 (and hence also #49) called
EntityAutocomplete::extractEntityIdFormAutocompletionResult()
, which doesn't actually exist, at least not in the latest 'entity_autocomplete' Form API element.EntityAutocomplete::extractEntityIdFromAutocompleteInput()
is what we want.Also fixed the 4 failures in #43/#44 (which had now actually become 5 failures, probably due to other patches having landed, most likely #2418613: Fix #0 bug in toUriString() method in Url class, clarify toString() vs toUriString(), which updated how we deal with (empty) fragments).
Comment #54
Wim LeersHaving this on the
LinkTypeConstraint
makes no sense. The leading slash is a pure widget-level decision.LinkItem
does not store 'user-path:' URIs with a leading slash. In fact,user-path:/node/add
does not even resolve to the expected URL, butuser-path:node/add
does.Hence this doesn't belong in the constraint, but at the widget. Once we have #2417647: Add leading slash to paths within 'user-path:' URIs, to allow 'user-path:' URIs to point to the <none> route, it'd be a different story.
This should only return the entity reference label if the user has access to the entity.
Debug leftover, but easy fix, of course.
Nice clean-up :)
For the same reasons as my remark about
LinkTypeConstraint
, this is wrong.Since you pinged me while I was posting a patch, I reviewed your patch, and thought this was a more elegant solution than the one I had. But this is wrong. So rerolling my patch with my original solution.
Comment #56
Wim LeersActually, is this even worth it? AFAICT
Url::fromRoute('<current>')
is more expensive. And since we need$route_match
anyway (see the next line of code after the change), we don't actually gain anything but a minor, arguable code legibility improvement.Perhaps this hunk snuck in from [#2418229]? It makes sense there, but is kind of out of scope here.
Furthermore, this causes the link to contain a leading slash, and for a shortcut to be created with that leading slash:
user-path:/<whatever the path is>
is what gets stored. This is the same problem as the above.The only reason
user-path:
URIs with leading slashes are working for you is that when they are processed byUrl::fromUri()
, it eventually hitsPathValidator::getUrl()
, which then simulates a request, and does this to do that:I.e. the leading slash is trimmed away, and hence still resolves to the expected route. But it's definitely not how
user-path
URIs are designed to work today. Again, we have #2417647: Add leading slash to paths within 'user-path:' URIs, to allow 'user-path:' URIs to point to the <none> route for that.Comment #57
Wim LeersFixed my patch as per #54.5. And did some docs fixes. Hopefully testbot will pick up this patch, because it didn't pick up #52 and #53…
EDIT: for clarity, the interdiff is against my latest patch, in #53, not dawehner's in #54.
Comment #58
dawehnerSorry but you are wrong. The test ensured that you can simply change the title of an existing shortcut. It should be possible for the user without changing the URL at the same time (see my standard.install change)
Comment #59
Wim LeersTime for an actual review!
Attached patch fixes all points raised, except the
<front>
and<none>
hunks.Next: addressing #58 and the other points that I raised.
I think these were added temporarily, to get the tests to pass?
AFAICT the goal was to not support
<front>
, but instead/
, which is much more logical than<front>
.These will trigger unhandled exceptions when using
entity:non_existing_entity_type/1
.This is not quite right… it violates the semantics of
user-path
:user-path:
points to the front page.user-path:#foo
points to#foo
on the front page.user-path:
is not designed to be able to link to just fragments, i.e. relative to whatever the current page is, i.e. it doesn't support the<none>
route.We have an issue to fix this: #2417647: Add leading slash to paths within 'user-path:' URIs, to allow 'user-path:' URIs to point to the <none> route. The changes made here introduce weird, inconsistent semantics. Let's do it right, by doing that other issue.
I thought that the conclusion from all prior discussion was:
Filed a follow-up for this: . If the above 2 points are wrong, then please update that follow-up.
With entity autocomplete, this makes far less sense. You'll end up with
http://drupalsite.com […]
, where[…]
is the autocomplete. So far so good. If you type a path, you're fine. But once you've used the entity autocomplete, it looks like this:http://drupalsite.com [Some article (1)]
.That makes far less sense.
Therefore I doubt the prefix is worth keeping.
This is the only test coverage we have for testing the link widget's 'entity:' URI support. We should add additional test cases now that we have entity reference autocomplete support.
This reimplements a lot of the widget logic in a test assertion function. That's not acceptable.
This talks about 2 types, but does 3 checks, hence there are actually 3 types of invalid entries.
Furthermore, the second if is very wrong, since
entity label (entity ID)
is now valid input. This is another example of the assertion function implementing too much logic.Comment #60
Wim LeersComment #61
Wim LeersIf that's what it was testing, then we should just omit
uri[0][value]
from the values being POSTed. Did that in this reroll.My change was correct, because the widget expects data in a different form than it is stored. The user enters
/node/add
, which is stored asuser-path:node/add
. The patches before mine strippeduser-path:
, and hence were postingnode/add
. This is wrong.The only reason the tests passed, is because
ShortcutTestBase
was changed to have wrong links saved as well (note that those are created without validation, which is why that was at all possible). Therefore, what was stored wasuser-path:/FOO
, hence stripping justuser-path:
resulted in/FOO
, which was indeed valid input for the widget. But note how this only worked because the data in the DB was wrong!Once the data is stored correctly, i.e.
user-path:FOO
, strippinguser-path:
results inFOO
, which is invalid input.So we have only two valid solutions:
str_replace('user-path:', '/', $shortcut->link->uri)
:user-path:FOO
->/FOO
, which is accepted by the widget$shortcut->link->uri
:user-path:FOO
->user-path:FOO
, which is accepted by the widgetWell, those two are valid, or we can simply not post the link field's value, which means the test runner will reuse the current value from the form. Which is what you say the test intended to test.
Those changes were wrong for the same reasons as above. They stored
user-path:/FOO
, which is invalid.Comment #62
Wim Leers… and here's the patch I forgot in #61.
Comment #63
Wim LeersStill working on addressing the
<front>
and<none>
stuff in my #59 review.In the mean time, this reroll makes sure that any input that begins with
/
,#
or?
does not trigger the autocomplete!Comment #64
dawehnerMeh, we discussed that multiple times that this issue is about a minimal implementation.
Comment #65
Wim LeersThis addresses the
<front>
and<none>
hunks I reviewed in #54.In #54.3, I said:
As is to be expected, there is no way to make the validation rules introduced in this patch work without also doing #2417647: Add leading slash to paths within 'user-path:' URIs, to allow 'user-path:' URIs to point to the <none> route.
The validation rules introduced in this issue say that a
user-path:
URI must begin with either/
,#
or?
. The first implies the<front>
route. The latter two both imply the<none>
route (i.e. URIs that render to the URLs<a href="#foo>…
and<a href="?foo=bar">…
respectively). But since the currentuser-path:
URI semantics cannot express the equivalent of the<none>
route, we cannot actually make this validation rule work in the current patch!Next: getting #2417647: Add leading slash to paths within 'user-path:' URIs, to allow 'user-path:' URIs to point to the <none> route to RTBC and committed, since that's effectively a blocker for this issue. Updated the IS and issue title to reflect the 2 blockers for this issue.
Comment #67
Wim LeersSome minor clean-up and docs updates. Plus a fix for the new test failure in #65.
Comment #68
alexpottComment #69
Wim LeersDiscussed with Alex, he didn't mean to remove the "[PP-2]". Restoring it.
#1959806: Provide a generic 'entity_autocomplete' Form API element is the first blocker, and is now RTBC! :)
#2417647: Add leading slash to paths within 'user-path:' URIs, to allow 'user-path:' URIs to point to the <none> route is the second, now up for review! :)
Comment #70
Wim LeersMere minutes later, #1959806: Provide a generic 'entity_autocomplete' Form API element got committed! :)
Comment #71
Wim LeersRerolled #67's do-not-test patch against HEAD.
Comment #72
Wim LeersComment #73
dawehner.
Comment #74
dawehnerI'm not sure whether its a good idea to not allow the usage of
<none>
and<front>
anymore.They are for example still used in other places, like block visibility, so I could imagine that people expect it to work the same here.
Comment #75
amateescu CreditAttribution: amateescu commentedI agree with #74, those special cases are quite useful and easy to remember for users. Would it be too much work to keep supporting them here?
Comment #76
Wim Leers#74 + #75: That would indeed mean a certain level of disconnect. It would not be much work.
But:
<front>
(<none>
has never actually been supported as a valid path… try it, you'll get a validation error), instead of getting a clean break with the past, a clearly different mental model, we end up with a mix of both — I think that's the worst of both worldsLinkWidget
) affect content authors.I think the harm mentioned in #74 is therefore strictly limited to site administrators, which is better than to harm content authors' mental model, which the proposed solution in #74 implies, IMHO.
If we feel strongly about this: can't we just update those other forms in analogous ways; not changing what they store, but changing what they present to the user?
Comment #77
webchickYes. For manually typed paths. Which will be a ~10% case, versus adding a link in your navigation menu to the home page, which is basically a 100% case.
It's not as though "the past" was done in a vacuum. It was done because non-technical site builders and especially content authors do not always know how URLs work. "/" is intuitive to you and me, but someone like my brother would never be able to figure that out. If it were documented, he would copy/paste it fine, but he would not understand why that meant "front page." Versus
<front>
is a plain-English word that's easy to understand and used in several UIs in core.Comment #78
webchickOK, #2417647: Add leading slash to paths within 'user-path:' URIs, to allow 'user-path:' URIs to point to the <none> route is in. Unpostponing this bad-boy.
Can I humbly request that since the idea to move from
<front>
to/
or whatever is going to require some discussion and also be a fair bit of work (in order to do consistently across all core UIs, which is what we would want to do), we postpone it to another non-critical issue and simply make this critical one match the existing behaviour?Comment #79
Wim LeersDid you know that
<front>
cannot be translated? Therefore it could indeed be argued it's easier to understand for English Drupal sites. But not for any translated site.From HEAD:
Yes, there's also the
node/add
example, but that's a literal example, whereas<front>
is a symbolic link, with a meaningful name. But there's only meaning in English. With a leading slash instead, we're putting all languages on equal footing.But if we really feel that it's very important to keep
<front>
, I can rework the patch to add that translation layer.Comment #80
Wim LeersStraight reroll, fixed a whole bunch of merge conflicts, was able to remove a bunch of overlapping hunks because things became simpler in this patch thanks to #2417647: Add leading slash to paths within 'user-path:' URIs, to allow 'user-path:' URIs to point to the <none> route.
Then had to add some fixes because of #2349071: EntityStorageException when trying to save a link over the maximum depth (which added a new test to update) and #2216271: Regression: Shortcut links access is not checked. The latter uncovered a hilarious bug:
<none>
is inaccessible by even UID 1, so a jumplink does not show up in the list of shortcuts… because<none>
doesn't specify requirements. So the very route needing the least access checking of all, because it doesn't correspond to an actual controller … failed access checking :DComment #81
webchickI'm not necessarily saying we should definitely *not* change it, I'm saying that whether to change it or not needs separate, dedicated discussion with pros/cons listed and weighed against one another. Your points are good ones for that disucssion, but they're going to get lost/missed in a critical issue that is supposed to be just about allowing the link field to autocomplete node titles.
Comment #82
dawehnerIts just sad how this issue went from: let's build a minimal implementation, get this in and refine later. Things like fixing the auto completion, IMHO would have belonged into its own refinement issue ... But so is work in the issue queue. I agree that none just worked in menu_link_config
Comment #83
Wim Leers#81: Alright. This merely implements what AFAIK was discussed and agreed upon before, but it's fair to expand that a bit to maintain "usability backwards compatibility" of course. Opened #2421941: Determine whether not only "/" but also "<front>" should be valid input for the Link widget.
#82: I thought this was the minimal implementation; I understood that the lack of support for entity types other than nodes was the "minimal" part. Perhaps that was wrong, in which case: apologies. I merely worked to drive this to completion ASAP as per what has been discussed in NJ and the calls leading up to NJ.
Rerolling to add back support for
<front>
as valid input.Comment #84
Wim LeersDone. Includes test coverage.
Comment #85
idebr CreditAttribution: idebr commentedIf
<front>
is a valid link, i think this string can stay as is?Note: user facing strings that use an example of an external url should no longer use drupal.org per #2418209: Replace user facing strings that use drupal.org as example of an external url.
Comment #86
Wim LeersI made sure
<front>
is allowed, but not that it is the recommended approach.webchick: what do you think?
Comment #87
webchick... I think I very explicitly asked at least twice to *not* change anything about that until we are done at the other issue. :)
The reason being is because unless this change is done everywhere we currently use
<front>
, it introduces a UI inconsistency which then need a a follow up to ensure it's "complete." The other issue will allow us to take a more holistic look at this and see if the pros of changing it warrant the benefits of the impact in beta.I don't want this change, which needs discussion on its own, crammed in with a change we *have* to commit. So yes, please remove it.
Comment #88
Wim Leers"Not change anything" is crystal clear, thanks, will do. That also means I will change it so that if a user *did* enter
/
, that upon editing it, he will see<front>
. Hence all old behavior is then preserved.P.S.: I'm sorry, I thought you were only referring to input. But it of course totally makes sense to keep UI strings unchanged also, otherwise we still have inconsistencies wrt the rest of core. Apologies.
Comment #89
Wim LeersDone.
Cleaned up and significantly expanded the number of test cases for
LinkFieldTest
's valid internal link entries.I kept the changes of
<front>
to/
in test code, to keep the usage of<front>
centralized in theLinkFieldTest
only, which makes future removal simpler, and to use the non-legacy input in tests that aren't explicitly testing the link widget. (As I said,LinkFieldTest
now *is* explicitly testing<front>
.)Comment #90
amateescu CreditAttribution: amateescu commentedThe latest patch looks awesome to me! Here's a quick review:
This should have a @todo that references #2419923: Port SA-CONTRIB-2013-096 to D8 because not showing any input at all is not correct. For example, ER in D7 contrib shows a "- Restricted access -" string.
Shouldn't these have static:: in front? I'm not sure, just asking :)
Can be removed?
How about adding another case here:
'entity:node/1' => $node->label() . ' (1)',
This would test that if the user entered entity:node/1 manually, the code that transforms it to "entity label + id" works, right?
Bunch of unnecessary changes :)
Comment #91
Wim LeersThanks for the review!
Comment #92
dawehnerDo we have to ensure that
<none>
also works here?Comment #93
dawehnerIn general this patch looks really ready beside of that, IMHO.
Comment #94
Wim Leers#92: no,
<none>
was never even supported in the UI, so I don't see why we need to add support for that now? Just type#jumplink
or?query=string#and_jumplink
— both of those are supported and tested.#93: great :)
Comment #95
dawehnerAlright, cool. Maybe it was just menu_link_config which had it.
Comment #97
idebr CreditAttribution: idebr commentedThis description was updated in #2418209: Replace user facing strings that use drupal.org as example of an external url. to remove any mentions of 'Drupal'. I think the original description can stay as is?
Comment #98
idebr CreditAttribution: idebr commentedWhile manually testing this I also noticed path aliases are not longer valid links unless they are prefixed with a slash, eg
/about
is valid butabout
is not. This behavior is not described in the issue summary and I did not really expect this change from an issue named 'Implement autocomplete UI for the link widget'. Is this the intended behavior? If so, will it break existing menu items and should it not require a change notice?Comment #99
Wim Leers#97: oops, then I resolved that merge conflict incorrectly, awesome catch! :)
#98: all paths must be entered with a leading slash, as the IS already indicates. It'd be highly consistent to enter non-alias paths with a leading slash and path aliases without.
The leading slash *only* is a UI thing, this issue/patch doesn't change what is stored. (That was changed in #2417647: Add leading slash to paths within 'user-path:' URIs, to allow 'user-path:' URIs to point to the <none> route and other issues, see #2407505: [meta] Finalize the menu links (and other user-entered paths) system.)
Fixing #97 and the test failure of #91. I can confirm that reversing the #91 interdiff makes the tests pass again. Investigating.
Comment #100
Wim Leers@todo
— I created the issue in @amateeescu's place).Since I only changed comments, back to RTBC.
Comment #101
Wim LeersCopied the wrong URL 3 times: once here, twice in the patch. Gah.
Comment #102
idebr CreditAttribution: idebr commented@Wim Leers thanks for your clarification
Nit that could be fixed on commit? s/loose/lose
Comment #105
amateescu CreditAttribution: amateescu commentedTest fails from #91, #100 and #101 are all testbot problems, the patch actually works fine!
Fixing #102 and hoping we'll get a better one this time :)
Comment #106
amateescu CreditAttribution: amateescu commentedI finally understood what the @todo mentioned in #90.3 / #91.3 was about :/
I initially saw it as a "target_type should be a 'entity_autocomplete' selection setting" but what it actually means is "target_type should be a widget setting, not hardcoded to 'node'". @dawehner, can you confirm that?
This also means that #2423093: Allow multiple target entity types in the 'entity_autocomplete' Form API element is actually about adding the possibility to select the target type and selection settings in the link widget, not about supporting multiple target types in the 'entity_autocomplete' form element.
Comment #107
dawehnerYeah its about not limiting this particular widget by default. It would be pretty helpful for contrib IMHO.
Comment #108
alexpottThe autocomplete blacklist does not appear to work. I create a node with the title "#twitter likes a #" and then link to this. The autocomplete works just fine. Also I'm not sure about the concept of the blacklist anyway since this is a totally valid node title.
Comment #109
amateescu CreditAttribution: amateescu commentedThe autocomplete blacklist works if you *start* typing with /, # or ? :)
Edit: and for node titles that start with one of those three characters, I think the idea was to support them enclosed in qoutes (i.e. start typing with "), just like strings that contain commas.
Comment #110
Wim LeersExactly what #109 says. I tried the #108 scenario, and I can't reproduce it.
(Note that if your node was titled "#yarhar fiddle deedee", then typing "#", "#y", "#ya" or even "#yarhar", it doesn't autocomplete. But typing "#yarhar" does autocomplete, and then the text field will contain "#yarhar fiddle deedee (1)". That's a leading hash. That's fine. It'll store the entity URI. Because it's not just a fragment anymore. That's still a consistent UX.)
Tentatively moving back to RTBC, since AFAICT that was just a misunderstanding.
Comment #111
effulgentsia CreditAttribution: effulgentsia commentedThat's a contradiction. I assume the second one was meant to say "yarhar"?
Yes. Because of the following:
Note that we check if an entity ID can be extracted first, so that takes priority.
I think it's okay to turn off autocompletion if the first character is "/", "?", or "#", since those are much more likely intended to be paths, query strings, and fragments, than they are to be the first character of a node title. And so long as you can still autocomplete the node title by just starting with some other character (e.g., "twitter" instead of "#twitter"), I think that edge case is sufficiently handled. But maybe that's a usability question that could benefit from broader testing, in which case I recommend committing it to get it in front of people, and then followups opened as needed.
Comment #112
webchickI tested this with two nodes, one more or less the same title as Alex's ("#twitter likes the # symbol") as well as "/dev/null: my home away from home." and a "coming soon" node called "Fish" with a URL alias of "fish." This is to simulate the use case of a path that changes entity types.
First, I went to create a link to the home page. (Also found out that I can't delete the default "Home" link, nor even change its title, which is a super annoying regression from Drupal 7, but not caused by this patch.) Linking to either
<front>
or/
worked, so we seem to be good there.Next, I went to create a link to the twitter post. As promised, typing in
#
kills the autocomplete. However, typing"#
shows the autocomplete, with that post first in the list. (Curiously, also "/dev/null: my home away from home" and "fish" which I don't understand.) Entering "twitter" (without the leading hash) also works. So I think this is fine, and expected.Similarly,
/de
== no autocomplete;"/de
== autocomplete, all options in the list. Basically, it seems like the"
character causes a TILT in the autocomplete field and it just starts returning the entire result set in alphabetical order. I am guessing this is a problem with the autocomplete implementation itself though, rather than something caused by this patch specifically, but it'd be good to just make sure.Tried typing the letter
d
, since that's only in the "/dev/null" post, and as expected it shows in the drop-down.Created a menu link "Fish" node via entering the path
/fish
. Worked fine. Then I edited the admin/content view's path to be "/fish." My "Fish" menu item still goes to the node. I delete the node and now /fish is a 404. Hm. Also, the menu link is gone. Why did that happen?Note: It's a very annoying inconsistency that in menu link I type
/fish
, but in Views UI I typefoo
for the exact same thing. We don't need to fix it in this patch, but we do need a follow-up to make all UIs in which you enter a path match with this one, IMO. Probably major.This can be an internal path such as /node/add or an external URL such as http://example.com. Enter <front> to link to the front page.
But it needs to lead with the primary interaction here, which is entering (part of) the title of a piece of content.Suggested change:
Start typing the title of a piece of content to select it. You can also enter an internal path such as /node/add, or an external URL such as http://example.com. Enter <front> to link to the front page.
(This doesn't have to be perfect; we can easily adjust it later in a normal/minor follow-up issue, even after release.)
"
character, unless that's caused by this patch.Looking very close!
Comment #113
dawehnerJust to remind you, this issue is just about implementing the autocompletion, everything else around it, is out of scope of this issue.
Afaik this is the way to move things along, small steps, not big steps which solves all the problems.
Well, we have all kind of code in menu_ui.module which ensures that in case you remove a node, the corresponding menu link is removed as well.
Sadly we don't distinct between a manually setup menu link and a menu link created on the node form itself, for which the behaviour is the expected one.
If we would have managed to get #2315773: Create a menu link field type/widget/formatter in, this would have been a trivial issue though, because we would have been able to distinct between the two cases really easily.
Comment #114
dawehnerBtw. its a little bit odd for example in the case of views, because in that case we don't support fragments / query strings anyway, because you don't enter
a link but rather a path, not a URI, really its a path. You can't create a view pointing to foo?bar=baz, but rather just to foo. Maybe it would help to
make that distinction clear, so that people would be able to understand what they exactly enter in links.
Comment #115
effulgentsia CreditAttribution: effulgentsia commentedFor #112.5: #2423913: Leading slash in link fields and views has different UX
Comment #116
webchickAFAIK this issue isn't blocked on anything that's out of scope. There's the change record, but that's required prior to commit of all patches that make changes from D7, critical or otherwise (that's done now, so removing the tag). And there's the help text change, but that's because this patch makes changes to the way in which the field works, so changing the field description is required to pass the docs gate (once again required of all patches, critical or otherwise). I would've just made the help text change myself, except I wasn't sure if some of the other weirdness I found when testing was due to this patch or not. If it's not, great, let's get this in. (Though my response to the second half of #113 is we should only invoke the behaviour if the link is to an entity:node/X-style link, but again not for this issue.)
The spin-off in #115 looks good. It might end up "won't fix" but we should at least discuss which is the least bad UX impact we can have.
Comment #117
Wim Leers#112:
LinkWidget
, that couldn't possibly be caused here. As dawehner also already indicated.#115: you may have set a new record for the longest issue title :D :D
Comment #118
alexpottWe have an eslint fail.
Comment #119
hussainwebAddressing #118. Since it is really minor, I think it is good to go to RTBC immediately.
Comment #120
dawehnerAwesome
Comment #121
alexpottThis issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 203ead6 and pushed to 8.0.x. Thanks!
Comment #123
yched CreditAttribution: yched commentedThis area has flown back to "above my head" heights :-), a couple side-remarks / questions below :
Looks like this will have unintended effects if there are several autocompletes on the page (i.e $autocomplete has more than one DOM element) ? Shouldn't we iterate on each element in $autocomplete individually ?
Parse error :-)
I might get this wrong, but if the field supports internal links, the widget provides a UI that only lets you pick entities ? I can't link to internal paths that are not entities ?
Also, if we "have to do the validation ourselves", shouldn't we set the 'entity_reference' element's #validate_reference to FALSE ?
Comment #124
Wim Leers/node/add
just as the description says.And we only store valid URIs, but we don't validate whether an entity URI points to an actual entity, because that would make the
Url
class dependent on the entity system. So we actually *do* want to keep#validate_reference
's default value of TRUE.Comment #125
yched CreditAttribution: yched commentedre 1.
I should have posted more context, but $autocomplete is :
var $autocomplete = $(context).find('input.form-autocomplete').once('autocomplete');
,so it contains all autocomplete elements in the context for the current Drupal.behaviors.attach() call.
Then the code builds one single autocomplete.options for all of them, and attaches it to all the autocompletes in $autocomplete. Thus, unless I'm missing something, the data-autocomplete-first-character-blacklist set in one autocomplete spills over to the all of the others ?
Comment #126
YesCT CreditAttribution: YesCT commented@yched #2438713: LinkWidget blacklist spills over to all autocomplete options to further document and discuss that.
Comment #127
yched CreditAttribution: yched commented@YesCT Thanks :-)
Comment #129
bharat.kelotra CreditAttribution: bharat.kelotra as a volunteer and commentedThe autocomplete not showing results by relevance. So I have a menu with link title "About" and there are other menu items also which contain the keyword "about". Number of links having about keyword is more than 10. So when I search for About I don't see the page "About" in the autocomplete list. I am attaching a screenshot for the same.
Proposed solutions:
Ideally we could have a link which can work as load more. So in autocomplete if there are more options which can be shown than we show a link to load more options.
Another possible solution is to add relevance with Link title starting with search keywords appearing first and than the links which have that keyword in between the title somewhere.
Comment #130
AnybodySame situation as #129 in a large project. The autocomplete is limited, but doesn't include the result the editors are looking for and the results are not ordered by relevance. So this is an issue on large projects.
I'm looking for a follow-up issue. If I shouldn't find one and link it here, me or the next who runs into this, should create a follow-up issue for things like: