PHP code example of fromholdio / silverstripe-gridfield-limiter

1. Go to this page and download the library: Download fromholdio/silverstripe-gridfield-limiter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fromholdio / silverstripe-gridfield-limiter example snippets


$gridField = GridField::create(
    'Widgets',
    'Widgets',
    $this->Widgets(),
    $gridConfig = GridFieldConfig_RecordEditor::create()
);

$gridConfig->removeComponentsByType(GridFieldAddNewButton::class);

$limit = 4;  // We want to limit this gridfield to 4 objects
$targetFragment = 'before' // Set gridfield target fragment value
$showLimitReachedMessage = true // We want to show the user a note when the limit is reached

$gridConfig->addComponent(
    new GridFieldLimiter($limit, $targetFragment, $showLimitReachedMessage)
);

$gridConfig->addComponent(
    new GridFieldAddNewButton('limiter-before-left')
);

$fields->addFieldToTab('Root.Testing', $gridField);