-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Link fields to be restricted to only internal or external URLs #5678
Comments
Here's a PR that adds this feature to core: backdrop/backdrop#4130 |
This makes sense... but I'm a bit concerned - would admins realize that they have to choose "Both", to get LINK_FRONT, LINK_EMAIL, LINK_NEWS - which link_validate_url() might also return? How about aliases, or absolute urls to internal pages? Might need some more testing, and I'd assume we should get a little more feedback here. |
I played in the sandbox 😄 ... There are some odd things with field setting combinations: First I tried setting to "internal only" and had "Validate URL" checked. All seemed good, until I tried Then turned "Validate URL" off in the field settings, but validation still happened... not as intended, I suppose. I'd only expect validation (/node/add/post), if Same for the field settings form. I'd rather expect that these radios only show up, if "Validate URL" is checked (/admin/structure/types/manage/post/fields/field_a_link). |
I'm getting a |
@indigoxela I've pushed a new commit that fixes the other link types. Now it'll only error if you've selected 'internal' but provide an 'external' URL, or if you've selected 'external' but provide an 'internal' or 'front' URL. In other words, 'front' is treated the same as 'internal' (since it is), and 'mail' and 'news' are always allowed (since it's too hard to determine if they're considered 'internal' or 'external'). As for the 'Validate URL' checkbox, that's a separate thing. It determines if the URL is checked to make sure it's a valid URL (e.g. @stpaultim Tugboat seems to be having issues ATM... |
Hm, I'm not convinced, that's correct. Current behavior is, that if "Validate URL" is off, no validation happens. This PR refines validation, using the same function. So link_validate_url runs twice if validation is turned on, only once when it's off. This seems odd to me. Anyway, I won't block this PR - may other people decide, if that's better or worse UX. 😉 |
I think this is a great feature, and I really like the making an External only link field disables the auto-complete on the field. I'm not sure if "Validate URL" should control the "URL type" field. Under-the-hood, I see that a URL basically must be validated in order to determine if it's internal or external, but as an end-user it feels like it's a different capability. In any case, we will need new test coverage for this option. |
I also like the feature, especially not using the autocomplete for external only link fields. Just wanted to look at it in the sandbox, but it's already expired. |
@olafgrabienski I've reset the sandbox so you can test now. |
I've just pushed some changes based on feedback in the PR. |
Yes @kiamlaluno, I think that the more "relaxed" behaviour that @olafgrabienski is describing is intentional. It is to allow people to create links to pages that have not been created yet. If that is not desired, then we should have a separate issue, since that behavior is pre-existing - not introduced with this PR. Speaking of separate issues, I believe that there has been some misunderstanding in the feedback left in the PR with re to the help text. @BWPanda I don't think that @quicksketch read @indigoxela's comment right. @indigoxela suggested that we should be adding this help text always - not to remove it altogether. Not having this does not provide any hints whatsoever for the content editors, which is not good UX (site builders will be forced to add descriptions in the field labels to distinguish them, like the screenshot):
I also believe that this help text (which will be hard-coded) should be added to the URL part of the link field - it should not be concatenated with the generic field description (which is allowed to be created/edited per field instance). The reason being that if you keep adding more links in a field that allows multiple values, then that help text will eventually be lost from the visible portion of the screen: Since repeating the same text for every field would increase noise and make the form longer, perhaps this hard-coded help text should only be added to the last instance of the link. Another though is to have the help text be "sticky", same as the field label as you are scrolling down the page: Anyway, all that can be a separate issue - don't want to hold this feature further. |
@klonos The previous version of this PR did have the help text always there, appended to whatever help text the user added manually. So since it was always there before, I think the suggestion was to remove it altogether... (but I'll let @indigoxela confirm/deny that). |
Sure 👍🏼 ...but this is what @indigoxela said in the PR:
|
...aah! English! ...I read that as "Shouldn't this always be there" 🤦🏼 🤦🏼 🤦🏼 ...mea culpa. |
...back to the issue though: not having any hints/indications and then throwing validation errors on form submission is bad UX. |
Yeah, but we don't do that in other situations either... For example, add a Number field and set the min/max values to 5/15 respectively. Create a node of that type and notice the lack of help text explaining what the min/max values are. I don't think we need to do this for the number field or the link field. If the individual web developer decides users will need this indication, they can add the help text manually I think. |
Interesting question, if we need automatic help text, or let the site architect decide. I'm not sure about it, but as an example the image field comes to mind, which combines automatic help text (e.g. allowed file size, or allowed dimensions) with custom text. |
Then we should be fixing these places too. Not having implemented best UX practices in other places should not be an excuse to not do it at all.
Let me start by saying that things aren't perfect, but they are improving as technology evolves, and we should be using what we have. For instance in that scenario above, the HTML5 number element on the page will have
Even if no JS is to be used, best UX would still be to add automatic help text there, pointing out the min/max allowed values. Anyway, if core committers have consensus to not include any help text with this change, I will file a follow-up to do that later (and for number fields with min/max restrictions 😉). |
Hello! I'm in favor of this feature. I have a Backdrop site with external-only link fields, and the forced autocomplete box is not ideal. Is this PR still in consideration? I'd be more than happy to help test. |
As discussed during the last weekly meeting (see https://www.youtube.com/live/HvOn6XVO_Z0?t=1573 for the topic of this issue), I'm advocating for the feature. I'll update the description accordingly. |
As I'm advocating for this feature request, I wanted to check if the PR still works for me, but its sandbox is expired. @BWPanda – are you able to rebuild the sandbox somehow? |
I closed and reopened the PR, which should make a new sandbox. |
Thanks for providing the new sandbox. The PR still works like a charm. Note: There are two failing checks. Not sure if / how related to the PR. Apart of that, there was a discussion if we should provide some help text for editors, see #5678 (comment). @klonos agreed to file a separate follow-up issue, if we have consensus to not include help text at this point. Conclusion: The PR is working. It would be great if somebody could take care of automated tests. We need also a code review. |
@olafgrabienski I added test coverage to the existing PR over at backdrop/backdrop#4130. The existing code looks good to me and if the tests pass, I think this can be approved. |
Thank you very much, @quicksketch, wonderful! Tests are passing, with one exception: spell check. edit: The PR is still working, btw. |
The spellcheck errors are unrelated; they seem to come from But I think it stands that unless there are any further reasons, this is ready to go! |
By @BWPanda, @indigoxela, @olafgrabienski, @klonos, @quicksketch, and @kiamlaluno.
I merged backdrop/backdrop#4130 into 1.x for 1.26.0. Thanks @BWPanda and @indigoxela for the original PR work, and thanks @olafgrabienski for shepherding this to completion. Thanks @klonos and @kiamlaluno for reviewing and support! |
Description of the need
If you want to add a Link field to a content type for storing URLs to external websites (e.g. like on the BackdropCMS.org Showcase nodes), users can still enter URLs for internal pages. Additionally, there's an autocomplete that displays a list of matching pages/content on your site (you may not want users seeing this list of content in this situation).
Advocate: @olafgrabienski
Proposed solution
It'd be nice if there was an option for Link fields to restrict them to either external or internal URLs (or both, as is the situation currently). Then you wouldn't have the autocomplete showing when you only wanted users entering external URLs.
Alternatives that have been considered
Drupal has the Advanced Link contrib module that achieves this, however it also does a bunch of other things too.
Additional information
Here's a screencast showing the issue on Backdrop's Showcase node form:
Draft of feature description for Press Release (1 paragraph at most)
Backdrop now optionally allows Link fields to be restricted to just external or internal URLs.
The text was updated successfully, but these errors were encountered: