Jump to content

Restrict adding items to repeater by role


Recommended Posts

You could try the Limit Repeater module to set a max number of rows. Alternatively, I have a feeling you may also be able to set a min and max number of rows within the field setup, if so you could set them to the same number. Or maybe use the Admin On Steroids module, enable the setting for it to add CSS classes for each admin page, then add CSS via the same module to hide the add new button.

Link to comment
Share on other sites

Hello @fox_digitalanimals

A solution with a hook and CSS.

First, in site/templates/admin.php, define a new CSS to include in admin:

/** @var Config $config */
$config->styles->add($config->urls->templates . "styles/test.css");

require($config->paths->core . "admin.php"); // this is already in admin.php, just take care of having it at bottom


.foobar .InputfieldRepeaterAddItem {
    display: none;

And add a hook in site/templates/admin.php to hide "add" button by adding a css class to repeater wrapper div:


    function (HookEvent $event) {
        /** @var Page $page */
        $page = $event->object->getPage();

        if ($page->template->name == 'myTemplate') { // Filter on this template

            /** @var InputfieldWrapper $wrapper */
            $wrapper = $event->return;

            /** @var InputfieldRepeater $myRepeater */
            $myRepeater = $wrapper->get('repeat'); // "repeat" is the field name of my repeater


You can finally add a condition on $user roles to add the css class:

if ($user->hasRole("theRole")){ // add the css... }


  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...