fromholdio / silverstripe-minigridfield
Installs: 2 617
Dependents: 2
Suggesters: 1
Security: 0
Stars: 5
Watchers: 3
Forks: 3
Open Issues: 0
Type:silverstripe-vendormodule
Requires
- fromholdio/silverstripe-gridfield-limiter: ^1.0.0 || ^2.0.0
- silverstripe/cms: ~4.2 || ~5.0
- silverstripe/vendor-plugin: ~1.0 || ~2.0
- stevie-mayhew/hasoneedit: ^2.3.0
- symbiote/silverstripe-gridfieldextensions: ^3.0.0 || ^4.0.0
README
A field that preconfigures and gently themes a GridField
to result in a "mini" inline grid field.
Two field types are included:
MiniGridField
HasOneMiniGridField
- use this to manage an object in a has_one relation
Auto-magically handles (preconfigures, with a few flags available to devs) orderable rows, add new multi class, versioning.
Requirements
- silverstripe-framework ^4.2
- symbiote/silverstripe-gridfieldextensions ^3.0
- fromholdio/silverstripe-gridfield-limiter ^1.0
Installation
composer require fromholdio/silverstripe-minigridfield
Screenshots
Complete Example
This is an example showing a has one, has many and many many:
use Fromholdio\MiniGridField\Forms\HasOneMiniGridField;
use Fromholdio\MiniGridField\Forms\MiniGridField;
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\ORM\DataObject;
class TestAdmin extends ModelAdmin {
private static $menu_title = 'Test';
private static $url_segment = 'test';
private static $managed_models = [
Radio::class,
Owner::class,
Presenter::class,
Listener::class,
];
}
class Radio extends DataObject {
private static $db = ['Title' => 'Varchar'];
private static $has_one = ['Owner' => Owner::class];
private static $has_many = ['Presenters' => Presenter::class];
private static $many_many = ['Listeners' => Listener::class];
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->replaceField('OwnerID', HasOneMiniGridField ::create('Owner', 'Owner', $this));
$fields->removeByName('Presenters');
$fields->insertAfter('Title', MiniGridField::create('Presenters', 'Presenters', $this));
$fields->removeByName('Listeners');
$fields->insertAfter('Title', MiniGridField::create('Listeners', 'Listeners', $this));
return $fields;
}
}
class Owner extends DataObject {
private static $db = ['Title' => 'Varchar'];
private static $has_many = ['Radio' => Radio::class];
}
class Presenter extends DataObject {
private static $db = ['Title' => 'Varchar'];
private static $has_one = ['Radio' => Radio::class];
}
class Listener extends DataObject {
private static $db = ['Title' => 'Varchar'];
private static $belongs_many_many = ['Radios' => Radio::class];
}
Replacing GridField universally
For projects that you'd like to replace all GridFields with MiniGridField, you can use the Injector to do so in a few lines of config:
SilverStripe\Core\Injector\Injector: SilverStripe\Forms\GridField\GridField: class: Fromholdio\MiniGridField\Forms\MiniGridField
Thanks & Acknowledgements
- https://github.com/silvershop/silverstripe-hasonefield
- https://github.com/satrun77/silverstripe-hasoneselector
- https://github.com/gorriecoe/silverstripe-linkfield
There are a few more, can't find them right now, will list them here soon. I've worked hard on getting this working how I want it, but took direction from some of the wonderful peeps and their code above, thanks.