PHP code example of youwilllikeit / silverstripe-gridfield-toolkit

1. Go to this page and download the library: Download youwilllikeit/silverstripe-gridfield-toolkit 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/ */

    

youwilllikeit / silverstripe-gridfield-toolkit example snippets


use YouWillLikeIT\GridFieldToolkit\Config\GridFieldConfig_ToolkitBase;
use YouWillLikeIT\GridFieldToolkit\Component\InlineEdit\Editor\{TextEditor, NumericEditor, ToggleEditor, SelectEditor, DependentSelectEditor};

$config = GridFieldConfig_ToolkitBase::create(50)
    ->withInlineEdit(
        new TextEditor('Title',  City::optionsFor($country)),
    )
    ->withUndo(5);

$config = GridFieldConfig_ToolkitBase::create(50)
    ->withFullscreen()
    ->withAccordion(fn (Order $o) => ['Customer' => $o->Customer()->Title, 'Notes' => $o->Notes])
    ->withMasterDetail(55)
    ->withKanban('Status', titleField: 'Title', cardFields: ['Customer.Title', 'Total']);

// Stash bulk actions: the selection survives paging, sorting and reloads.
$orders = GridFieldConfig_ToolkitBase::create(25)
    ->withStashBulk(
        new DeleteBulkAction(),
        new SetFieldBulkAction('archive', 'Archive', 'Status', 'archived'),
        new CallbackBulkAction('mail', 'Send reminder', fn (Order $o) => $o->sendReminder()),
    )
    ->withMasterSelect('OrderItems')            // master: row click filters the slave
    ->withTransferSource()                      // rows can be dragged to another grid
    ->withViewStatePersister();                 // remember sort / filter / page

$items = GridFieldConfig_ToolkitBase::create(25)
    ->withLinkedFilter('OrderID', emptyUntilSelected: true, masterLabel: 'Orders')
    ->withTransferTarget(['Orders'], function (DataObject $item, GridField $target, string $mode): void {
        $item->OrderID = /* the order this grid belongs to */;
    });

$config = GridFieldConfig_ToolkitBase::create(25)
    ->withColumnManager(locked: ['Title'], defaultHidden: ['CreatedAt'])
    ->withHeaderHelp(['Status' => _t('Order.STATUS_HELP', 'Where the order is in its life cycle')])
    ->withTranslationStatus()                 // Fluent, when installed; or pass a TranslationStatusProviderInterface
    ->withNestedRelation('Items', 'Items')    // "Items (3)" button -> modal with the record's Items tab
    ->withViewStatePersister();               // also remembers the chosen columns