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

How to add a max number of Links? Does Linkfield have any configuration to support it? #37

Open
sephyhe opened this issue Apr 24, 2023 · 2 comments

Comments

@sephyhe
Copy link

sephyhe commented Apr 24, 2023

Hi there,

I was wondering if you could kindly let me know if Linkfield supports a maximum number of links? I understand that having a maximum number of links could be quite useful in preventing any potential issues with breaking the FED layout.

I have attempted to find related information in the source code, however, I was unable to locate any. Would it be possible to add a parameter to support this feature and utilize it to remove the "add new" button when the gridfield reaches the maximum number? If you feel that this is a viable solution, I would be more than happy to create a pull request for you.

Thank you

@elliot-sawyer
Copy link
Owner

elliot-sawyer commented Apr 24, 2023

There is no maximum number of links. Best way to enforce this would be within your own project code. I've done this in the past by placing a .Limit(N) rule in my loop, for example:

<% loop MyLinks.Limit(5) %>
...
<% end_loop %>

You can use the drag/drop ordering to manage the list in the CMS, and add a description reminding CMS users that only the first N items will be shown on the website. That way they can actually add as many as they'd like.

@GuySartorelli
Copy link
Contributor

GuySartorelli commented Sep 26, 2023

The LinkField, when used with a many relation, is effectively a gridfield. You might be able to use https://github.com/fromholdio/silverstripe-gridfield-limiter or https://github.com/webbuilders-group/silverstripe-limitedrelationsgridfield (or adapt some of the code if neither of those work out of the gate) to limit the number of links that can be added to the field.

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

3 participants