Skip to content
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

Feature Request: Disable internal / same domain URLs #269

Open
ul8 opened this issue Aug 10, 2023 · 3 comments
Open

Feature Request: Disable internal / same domain URLs #269

ul8 opened this issue Aug 10, 2023 · 3 comments

Comments

@ul8
Copy link

ul8 commented Aug 10, 2023

Context

We want users to set links to Craft content by using Entry relations, not URLs, as it is more durable in case we later change the Entry URI format or migrate the domain.

At the same time we have to make the URL option available so they can link to external sites.

Suggestion

Add a check box in the URL options: "Prevent users from adding internal URL links"

When a user tries to save a URL that starts with the PRIMARY_SITE_URL, the validation fails with a message
"Could not save URL. For internal links, please select an entry instead of entering a URL"

@jamesmacwhite
Copy link

jamesmacwhite commented Aug 23, 2023

If it helps. While I don't use this plugin directly, you could look at implementing custom validation rules on an entry or if you have a linkfield in a matrix block, matrix block validation by checking the block type and linkit field type for the URL type and then doing a regex match with the primary site URL to catch these scenarios.

We have a similar scenario where the URL field has used a hard coded domain for Entry content. I implemented custom validation errors to catch this scenario.

You could also look at extending the validation rules of the linkfield as well to implement a similar outcome.

@ul8
Copy link
Author

ul8 commented Aug 24, 2023

@jamesmacwhite Thanks, those are some good ideas! A custom validation rule works for sure.

I still think this should be a very common requirement (that many probably aren't even aware of). Having this as an option right in the plugin would make it easier and encourage best practices.

@jamesmacwhite
Copy link

jamesmacwhite commented Aug 29, 2023

I don't disagree with you on it being a useful feature, I just happened to come across your issue post while looking at this plugin and thought it was very similar to a scenario I had been working with, quite by chance really!

I might end up looking at using this plugin instead of Linkit, given the bug with multi-site entry linking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants