fox_digitalanimals Posted November 17, 2023 Posted November 17, 2023 Hello everyone, I'm pretty new to Processwire, setting up my first system for a client and wonder, if it is possible to restrict adding items to a repeater / remove the "Add new" button. Thanks in advance Torsten
cb2004 Posted November 17, 2023 Posted November 17, 2023 Within the field there will be a tab for 'Access'. You should be able to do what you need to do in there.
fox_digitalanimals Posted November 17, 2023 Author Posted November 17, 2023 Yes, I can restrict editing complete and only show the items inside. But I want the client / editor to be able to edit the content of the repeater items. I only don't want them to add new items. Is this possible?
taotoo Posted November 17, 2023 Posted November 17, 2023 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.
cb2004 Posted November 17, 2023 Posted November 17, 2023 I have never used the access for fields before. I am sure you could do this with a hook, but sounds like it should be part of the core as well.
da² Posted November 17, 2023 Posted November 17, 2023 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 site/templates/styles/test.css: .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: $this->addHookAfter("ProcessPageEdit::buildFormContent", 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 $myRepeater->addClass('wrap:foobar'); } }); You can finally add a condition on $user roles to add the css class: if ($user->hasRole("theRole")){ // add the css... } 1
fox_digitalanimals Posted November 23, 2023 Author Posted November 23, 2023 Thank you @da²! That works well! ? 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now