LimitRepeater by Robin S

Allows limits and restrictions to be placed on selected Repeater fields.

LimitRepeater

Allows restrictions and limits to be placed on Repeater fields.

For any Repeater field you can limit the number of items that may be added and also prevent the use of drag-sorting, toggling of published state, and the trashing of items. There is also an option to hide the clone button when the limit is reached.

Usage


Install the LimitRepeater module.

Since v0.2.0 the module settings are configured at Setup > Fields > [your Repeater field]. The settings are contained within the "Restrictions" fieldset on the "Details" tab.

Module config

Please note that the restrictions limits are applied in Page Edit with CSS/JS so should not be considered tamper-proof.

Setting restrictions via a hook

Besides setting restrictions in the field settings, you can also apply or modify restrictions by hooking LimitRepeater::checkRestrictions. This allows for more focused restrictions, for example, applying restrictions depending on the template of the page being edited or depending on the role of the user.

The checkRestrictions() method receives the following arguments:

  • $field This Repeater field
  • $inputfield This Repeater inputfield
  • $page The page that is open in ProcessPageEdit

The method returns an array of restrictions for the Repeater field. An example of a returned array:

Restrictions

Example hook

Prevent non-superusers from trashing any items in "my_repeater_field":

$wire->addHookAfter('LimitRepeater::checkRestrictions', function(HookEvent $event) {
    $field = $event->arguments('field');
    $restrictions = $event->return;
    if($field->name === 'my_repeater_field' && !$this->user->isSuperuser()) {
        $restrictions['notrash'] = true;
    }
    $event->return = $restrictions;
});

Upgrading from < v0.2.0


There are two major changes to be aware of when upgrading from earlier versions of the module.

  1. The settings are no longer defined on the module config page, but rather in the field settings of each Repeater field: Setup > Fields > [your Repeater field]. If you visit the module config page you'll find shortcuts to the settings for each Repeater field.
  2. In earlier versions you could apply restrictions to a particular role. This is still possible but is now handled by hooking LimitRepeater::checkRestrictions as this is a more flexible and powerful approach. If you were applying restrictions to a particular role or roles you'll need to add hook code to achieve the same effect after you upgrade the module. See the hook information above in this readme.

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Twitter updates

  • New main/master version of ProcessWire that has more than 220 commits, resolves more than 80 issues, adds numerous new features, performance improvements and optimizations, and consumes HALF the disk space of our previous release— More
    13 May 2022
  • Summary of weekly core updates for 22 April 2022 More
    22 April 2022
  • ProcessWire 3.0.198 core updates: in this post we take a closer look at 3 useful new features added in this version— More
    15 April 2022

Latest news

  • ProcessWire Weekly #418
    In the 418th issue of ProcessWire Weekly we'll cover recent highlights, share some tips and tricks, and check out the new master version of ProcessWire, 3.0.200. Read on!
    Weekly.pw / 14 May 2022
  • ProcessWire 3.0.200 new master/main version
    This new main/master version has more than 220 commits, resolves more than 80 issues, adds numerous new features, performance improvements and optimizations, and consumes HALF the disk space of our previous release. This post covers all the details.
    Blog / 13 May 2022
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.