-
Notifications
You must be signed in to change notification settings - Fork 646
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
[5.x]: Link field URL will no longer accept a root-relative string. #15579
Comments
I'm dealing with this as well. We didn't see anything mentioned in the release notes and didn't catch it in testing. Now we have it deployed to production and can't edit any of our entries that have URL (now Link) fields. We are dead in the water until this is fixed. We were told we could change those link fields to text fields but that doesn't seem right either. I agree, a relative url starting with a slash should pass validation as it has for many years with the URL field type. |
We're going to need this to be fixed for in-page anchors too (i.e., URIs starting with a |
Heck, even if they leave it as-is and just give us an advanced regex setting to override the validation logic, that would be fine, but we need something, and quick. We can't edit any entries currently. Argh. |
Yes, we have the same problem with the base url like The Anchor thing you could fix with an extra field, its not the nicest way but okay in some cases. |
This is a big deal for some of us that relied on relative URLs in this field type. This is a breaking change and there was no warning or anything in the release notes. If this won't be reverted, what is the best path forward here? For us, this is preventing us from adding a new product to our main navigation and it's a holiday week for us. It's a big deal. |
hey, I know this is not ideal - but have you already tried a temporary fix with Events and just disable the validation for Link field with type URL? E.g. ![]() See https://craftcms.com/docs/5.x/extend/events.html#event-code-generator |
@mandrasch Hmm. I've not used Events before, but it looks promising. I'm going to read up on it a bit and see if CraftQuest or YouTube Has some videos explaining it a bit more. I'm not quite sure how to implement these events. Assuming I'd have to do it through a custom plugin? |
@jacobgraf Yes, Plugin or Module (even easier). I would just use a module, you can generate one with |
(And if you want to use a subfolder for your module, check this comment - I was a bit confused in the beginning on how to use the generator correctly ;-)) |
@mandrasch Cool. Thanks! I will play around, but just wish they would come out with an official fix. I'm annoyed that this breaking change was pushed out and wasn't even in the release notes. At a minimum, we should be able to override the default RegEx for these types of fields if we want our own validation rules to take over. |
@jacobgraf I understand the frustration, guess this will be addressed soon by the craft team. 🙂 (By the way - craft is very flexible, it might already be possible to override an existing validation rule and add your own regex. Just haven't found a detailed example yet for a normal field, but here is an example for overriding user field validation https://nystudio107.com/blog/extending-craft-cms-with-validation-rules-and-behaviors) |
Sorry about this – support for root-relative URLs and anchors were overlooked when working on the Link field. I’ve added new “Allow root-relative URLs” and “Allow anchors” settings to Link fields for Craft 5.4, which can be enabled to opt into allowing those. If you need this right away, you can switch to the "craftcms/cms": "5.4.x-dev as 5.4.0-alpha", |
@brandonkelly Thanks. I was mid-process of building a custom module. I'm a bit leery of opting into dev or alpha since this site is in production. A couple of quick questions.
I am thinking this is the event like @mandrasch mentioned above, but I'm not quite sure what to put into the function to get it to work how I want?
Thanks again. Didn't want to be an annoyance, but this one has really put us in a bind for the last week. |
I don’t think clearing out validation errors would actually work. There are internal changes to the Link field PHP and JS, plus the URL link type, that were required to get the fields actually handling root-relative and anchor links properly. We’re going to fast track 5.4 for this and a couple other things that need to be released sooner than later – possibly as soon as later this week or next week. |
@brandonkelly Good to know. I have been told I need to get the content updated today as far as our site goes. Unless you can suggest some other work-around to be able to save my entries that have link fields on them, I may have to roll the dice on the dev release. I'll wait to hear back from you and then decide which path to take. Like I said, with a big holiday coming up and this being content for an e-comm site, I just need to get it working and then can wait for the official launch of 5.4 in stable. |
@jacobgraf You could switch the field type to Plain Text for now, and back to Link once 5.4 is out. You’d just need to ensure your templates aren’t taking advantage of any of the new Link templating features. |
@brandonkelly Sounds good. I will do that then. We haven't refactored any code since the update so it would just be using the old URL field capabilities. Thanks again for all your help here. |
@brandonkelly All converted. So far, so good! I'll watch for the 5.4 official release. Thanks again! |
@brandonkelly Thanks. That is great! |
Thanks for the fix Brandon. Out of curiosity though, why are we making options out of these? I can't think of any circumstance where anyone would want to limit editors to not use anchors or or relative links? Surely anything that can go in an |
@thisisjamessmith Root-relative URLs and anchors have limited use compared to absolute URLs. You can’t include them in an RSS feed or HTML email body, for example. |
@brandonkelly Fair enough! I'd really expect those kind of scenarios to be handled by a developer though - not sure it should be Craft's job to be opinionated in that respect. The situations where we'd use a dedicated Link field will generally (always?) be situations where we have control over the output (unlike a link button in a rich text field), so prepending a domain name to those links for external syndication scenarios would be straight-forward. Are there any plans to allow the Link field's functionality inside Table fields? That's probably my most common usage of it (e.g. for outputting multiple button-style links). I notice that at the moment in a Table field it is still listed as a "URL" field, and has less functionality. |
@thisisjamessmith Eventually yeah. Table fields are due for a major refactor which would involve letting them have custom column types, like Link. |
@thisisjamessmith: We have noticed that too. We look forward to P&T implementing this option. |
Craft 5.4.0 is out with those changes. |
@akukral That’s a separate bug. Can you post a new GitHub issue about it? |
What happened?
Description
Prior to 5.3 we could use root-relative links in the URL field type, now the new "Link" field.
On sites that use root-relative links extensively this will cause validation errors when attempting to save.
We don't want to use absolute URLs for internal links because they need to work on both dev and live environments, which use different TLDs.
We don't want to update all content to use element relationships because 1) Not everything on a given site is necessarily a URL-addressable Entry/Category/Asset, and 2) Your docs state that elements are not currently eager-loadable, and 3) it'll take ages on old sites that already have lots of populated URL fields.
Can we please just allow URLs that start with a slash to maintain backwards compatibility? (We'll have lots of Craft 3 & 4 sites to upgrade soon and this will be a show-stopper for those).
Craft CMS version
5.3.4
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
No response
The text was updated successfully, but these errors were encountered: