Add an option to limit multiple site setting entities

Created on 8 December 2024, 4 months ago

Problem/Motivation

Add the option to limit a site setting entity type to a certain number of entities, so the 'Add another' link does not appear when that number of entities is met.

Steps to reproduce

Proposed resolution

Create a patch.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇧🇪Belgium aren33k

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @aren33k
  • 🇧🇪Belgium aren33k

    I created this patch, needs some more review.
    At this moment it just handles the 'Add another', depending on the amount of entities.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇬🇧United Kingdom scott_euser

    Thanks very much for the contribution.

    The idea is makes sense, but I think we need to do several things as well/instead:

    1. Modify the site_settings_entity_operation() in the .module file to conditionally control when 'Add another' is shown by also counting current number if a limit is set
    2. Instead of the JavaScript I think its fine to just rely the above, the button will stop existing once total is reached. If the user has left the list page open then the behaviour matches the current state when a user goes to the 'Add another' route on a non-multiple Site Setting; they get access denied. We could always change that in a follow-up to be a screen explaining why no additional is allowed (e.g. maximum number reached message) and redirect back to list.
    3. Follow what Drupal Core does when create a Field allowing the setting Unlimited vs Limited + 'Allowed number of site settings' when 'Limited' is shown so we match that DX (see attached screenshot)
    4. Update site_setting_entity_type.schema.yml to add these new fields
    5. Add an update hook to set the selection to 'Unlimited' for all existing site_setting_entity_type so status quo is maintained by default
    6. Will need to add test coverage as well

    The first bits looks like from your contribution you might know enough but happy to help if you get stuck. You can also find me on Drupal Slack as scott_euser. The latter two in the list above, I am not sure how experienced you are, so I would be happy to either add that in for you or point you in the direction of examples (as you prefer).

    It would also be good to do this as a Merge Request as its easier to review + gets the automated tests running. You can use the 'Create issue fork' in the issue header, my typical approach is:

    1. Go to module homepage -> version control and get the 'git clone' link (or do it from 'Source code' link on module homepage to get into Gitlab)
    2. Delete my projects web/modules/contrib/module_name folder and git clone into there instead
    3. Use the commands from the issue (ie, those above) to switch to the fork + check out the branch
    4. Do the work in the branch and push to the branch

    To switch from patch to branch, you can copy your patch to the cloned module directory and do a 'git apply filename.patch'.
    Again let me know if you need any help here getting going. Happy to help

  • 🇬🇧United Kingdom scott_euser

    Ah and the screenshot promised :)

  • Status changed to Needs work about 2 months ago
  • 🇧🇪Belgium aren33k

    @scott_euser Thanks for the info, will work on this coming weeks.

  • 🇧🇪Belgium aren33k

    Updated patch for v 2.02.

Production build 0.71.5 2024