Robin S Posted June 27, 2017 Share Posted June 27, 2017 Restrict Repeater Matrix Allows restrictions and limits to be placed on Repeater Matrix fields. Requires ProcessWire >= v3.0.0 and FieldtypeRepeaterMatrix >= v0.0.5. For any matrix type in a Repeater Matrix field you have the option to: Disable settings for items (cannot change matrix type) Prevent drag-sorting of items Prevent cloning of items Prevent toggling of the published state of items Prevent trashing of items Limit the number of items that may be added to the inputfield. When the limit is reached the "Add new" button for the matrix type will be removed and the matrix type will not be available for selection in the "Type" dropdown of other matrix items. Hide the clone button when the limit for a matrix type has been reached. Note that in PW >= 3.0.187 this also means that the copy/paste feature will become unavailable for the matrix type. Please note that restrictions and limits are applied with CSS/JS so should not be considered tamper-proof. Usage Install the Restrict Repeater Matrix module. For each matrix type created in the Repeater Matrix field settings, a "Restrictions" fieldset is added at the bottom of the matrix type settings: For newly added matrix types, the settings must be saved first in order for the Restrictions fieldset to appear. Set restrictions for each matrix type as needed. A limit of zero means that no items of that matrix type may be added to the inputfield. Setting restrictions via a hook Besides setting restrictions in the field settings, you can also apply or modify restrictions by hooking RestrictRepeaterMatrix::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 Matrix field $inputfield This Repeater Matrix inputfield $matrix_types An array of matrix types for this field. Each key is the matrix type name and the value is the matrix type integer. $page The page that is open in ProcessPageEdit The method returns a multi-dimensional array of matrix types and restrictions for each of those types. An example of a returned array: Example hooks Prevent the matrix type "images_block" from being added to "my_matrix_field" in a page with the "basic-page" template: $wire->addHookAfter('RestrictRepeaterMatrix::checkRestrictions', function(HookEvent $event) { $field = $event->arguments('field'); $page = $event->arguments('page'); $type_restrictions = $event->return; if($field->name === 'my_matrix_field' && $page->template->name === 'basic-page') { $type_restrictions['images_block']['limit'] = 0; } $event->return = $type_restrictions; }); Prevent non-superusers from trashing any Repeater Matrix items in "my_matrix_field": $wire->addHookAfter('RestrictRepeaterMatrix::checkRestrictions', function(HookEvent $event) { $field = $event->arguments('field'); $type_restrictions = $event->return; if($field->name === 'my_matrix_field' && !$this->user->isSuperuser()) { foreach($type_restrictions as $key => $value) { $type_restrictions[$key]['notrash'] = true; } } $event->return = $type_restrictions; }); http://modules.processwire.com/modules/restrict-repeater-matrix/https://github.com/Toutouwai/RestrictRepeaterMatrix 16 Link to comment Share on other sites More sharing options...
cjx2240 Posted July 6, 2017 Share Posted July 6, 2017 Unfortunately, this just completely broke the field edit page for me! Link to comment Share on other sites More sharing options...
Robin S Posted July 6, 2017 Author Share Posted July 6, 2017 @cjx2240, sorry to hear that. Can you give some more information please... Is the "who_we_are" field a Repeater Matrix field? Do you have the latest version of Repeater Matrix installed - v0.0.4? Do you have debug mode enabled in /site/config.php? If not please enable and let me know if you see any error messages when you try and edit the field. If you don't see any error messages still, please install Tracy Debugger, tick the "Backend" option for "Show Debug Bar", and check for errors when you try and edit the field, as in the screenshot below: Thanks. 2 Link to comment Share on other sites More sharing options...
cjx2240 Posted July 7, 2017 Share Posted July 7, 2017 Updating RepeaterMatrix from 0.0.3 to 0.0.4 resolved the issue, thanks. 1 Link to comment Share on other sites More sharing options...
Robin S Posted July 7, 2017 Author Share Posted July 7, 2017 9 minutes ago, cjx2240 said: Updating RepeaterMatrix from 0.0.3 to 0.0.4 resolved the issue, thanks. Thanks for letting me know. I have updated the module to set a minimum version requirement for FieldtypeRepeaterMatrix. 2 Link to comment Share on other sites More sharing options...
Zeka Posted September 30, 2017 Share Posted September 30, 2017 Hi @Robin S Have not tried this module yet, but I'm curious is it possible to restrict matrix types per template basis? Link to comment Share on other sites More sharing options...
Robin S Posted September 30, 2017 Author Share Posted September 30, 2017 4 hours ago, Zeka said: Have not tried this module yet, but I'm curious is it possible to restrict matrix types per template basis? Yes, see the "Setting restrictions via a hook" section of the first post / readme. Link to comment Share on other sites More sharing options...
Juergen Posted February 12, 2018 Share Posted February 12, 2018 Cannot install the module There is always the message that FieldtypRepeaterMatrix is not the correct version, but I have downloaded it today from the modules directory - so it must be ok. Link to comment Share on other sites More sharing options...
Robin S Posted February 12, 2018 Author Share Posted February 12, 2018 8 hours ago, Juergen said: There is always the message that FieldtypRepeaterMatrix is not the correct version, but I have downloaded it today from the modules directory - so it must be ok. This module requires Repeater Matrix which is part of the Profields bundle. The Matrix module you have shown in your screenshot is something completely different. Link to comment Share on other sites More sharing options...
Juergen Posted February 13, 2018 Share Posted February 13, 2018 Oh, sorry - my fault. I use the 2D repeater matrix from Kongondo. Link to comment Share on other sites More sharing options...
Robin S Posted July 21, 2019 Author Share Posted July 21, 2019 v0.1.4 released. This version adds support for some new features added in Repeater Matrix v0.0.5 - you can disable the settings for matrix types (so items cannot change their matrix type), and when the limit for a type is reached it becomes unavailable for selection in the type dropdown of other matrix items. The module now requires Repeater Matrix >= v0.0.5. If you are using Repeater Matrix v0.0.4 or older then there is no need to upgrade Restrict Repeater Matrix as the new features in v0.1.4 are only applicable to Repeater Matrix v0.0.5. 2 Link to comment Share on other sites More sharing options...
Didjee Posted January 28, 2022 Share Posted January 28, 2022 Hi @Robin S, Thanks a lot for this module! Exactly what I was looking for ? Version 0.0.8. of RepeaterMatrix introduced the 'insert before' and 'insert after' buttons. If I limit the use of matrix types to 1 item per type, it's still possible to add a new item via 'insert before' and 'insert after' (see screenshot below). Is it possible to prevent this? Link to comment Share on other sites More sharing options...
Robin S Posted January 28, 2022 Author Share Posted January 28, 2022 13 hours ago, Didjee said: Version 0.0.8. of RepeaterMatrix introduced the 'insert before' and 'insert after' buttons. If I limit the use of matrix types to 1 item per type, it's still possible to add a new item via 'insert before' and 'insert after' (see screenshot below). Is it possible to prevent this? It's not just the new insert before / insert after features, it's also all the new options for adding items that would need attention. It looks like a lot of work to support and probably it still won't work reliably for all the options, e.g. custom. Sorry, but it's unlikely I'm going to get around to spending the time on this in the foreseeable future. It's probably not practical for a module like Restrict Repeater Matrix to exists when the base module (Repeater Matrix) can be changed at any point. Repeater Matrix is a commercial module so Ryan should be responsive to the needs of its users - I suggest submitting requests to Ryan for the features you want to see. I'll add a note at the top of the readme about the incompatibility with recent updates to Repeater Matrix. 1 Link to comment Share on other sites More sharing options...
Robin S Posted January 30, 2022 Author Share Posted January 30, 2022 On 1/29/2022 at 12:55 PM, Robin S said: Sorry, but it's unlikely I'm going to get around to spending the time on this in the foreseeable future. Well, I couldn't help myself. ? Plus it wasn't as bad as I expected. @Didjee, the insert buttons and other features from Repeater Matrix v7/8 should work in the newly released Restrict Repeater Matrix v0.2.0. 3 3 Link to comment Share on other sites More sharing options...
Didjee Posted January 30, 2022 Share Posted January 30, 2022 Quote the insert buttons and other features from Repeater Matrix v7/8 should work in the newly released Restrict Repeater Matrix v0.2.0. @Robin S wow, this is really great! Thanks for spending your weekend hours on this update ? 1 Link to comment Share on other sites More sharing options...
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