Download the PHP package fromholdio/silverstripe-gridfield-limiter without Composer
On this page you can find all versions of the php package fromholdio/silverstripe-gridfield-limiter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fromholdio/silverstripe-gridfield-limiter
More information about fromholdio/silverstripe-gridfield-limiter
Files in fromholdio/silverstripe-gridfield-limiter
Package silverstripe-gridfield-limiter
Short Description Limit number of records that can be added to a SilverStripe GridField
License BSD-3-Clause
Homepage https://github.com/fromholdio/silverstripe-gridfield-limiter
Informations about the package silverstripe-gridfield-limiter
silverstripe-gridfield-limiter
Small module to limit number of records that can be added to a SilverStripe GridField.
Important - this module does not prevent records being added at an ORM/code-level in any way.
Instead, it manipulates the GridField
UI to allow developers to hide controls like GridFieldAddNewButton
once a set limit is reached, preventing CMS users from adding more records via that grid field.
- It hides
GridFieldAddNewButton
,GridFieldAddExistingAutocompleter
and otherGridFieldComponent
s you define, if the limit is reached - Optionally, if limit has been reached, a message is also presented to the user notifying them of this
Requirements
SilverStripe 5+
Installation
composer require fromholdio/silverstripe-gridfield-limiter
Detail
- Add
GridFieldLimiter
to yourGridFieldConfig
, and define a target fragment (defaults tobefore
) - It will create two new target fragments,
limiter-before-left
andlimiter-before-right
(before
comes from the defined target fragment) - You can now fill these two fragments with grid field components, like a
GridFieldAddNewButton
on the left and aGridFieldAddExistingAutocompleter
on the right, which will all be hidden (via css) from the CMS user once the grid field reaches its row limit - If enabled, a message will be displayed to the user telling them to remove an item before they add a new one
Per the note above, this does not in anyway validate the number of objects in a relationship or prevent an object being added - it's just a cheeky way to implement a limit for CMS users managing a grid field.
Under-limit screenshot
Limit-reached screenshot
Usage example
We have a standard GridField
using a GridFieldConfig_RecordEditor
and will add a limit to it.
Remove the GridFieldAddNewButton
in preparation to add one within our GridFieldLimiter
:
Add the GridFieldLimiter
Add a GridFieldAddNewButton
(and/or any other components) you would like displayed while under limit but hidden when limit is reached, using the limiter
target fragment.
That should work!