Added more documentation for nested gridfields.

This commit is contained in:
Niklas Forsdahl 2024-05-15 08:57:58 +03:00
parent a9b0a70155
commit c476cedff0
2 changed files with 31 additions and 0 deletions

View File

@ -18,6 +18,8 @@ This module provides a number of useful grid field components:
features. features.
* `GridFieldTitleHeader` - a simple header which displays column titles. * `GridFieldTitleHeader` - a simple header which displays column titles.
* `GridFieldConfigurablePaginator` - a paginator for GridField that allows customisable page sizes. * `GridFieldConfigurablePaginator` - a paginator for GridField that allows customisable page sizes.
* `GridFieldNestedForm` - allows nesting of GridFields for managing relation records directly within
a parent GridField.
## Installation ## Installation

View File

@ -166,3 +166,32 @@ $grid->getConfig()->addComponent(GridFieldNestedForm::create());
// Usage with custom relation // Usage with custom relation
$grid->getConfig()->addComponent(GridFieldNestedForm::create()->setRelationName('MyRelation')); $grid->getConfig()->addComponent(GridFieldNestedForm::create()->setRelationName('MyRelation'));
``` ```
You can define your own custom GridField config for the nested GridField configuration by implementing a `getNestedConfig`
on your nested model (should return a `GridField_Config` object).
```php
class NestedObject extends DataObject
{
private static $has_one = [
'Parent' => ParentObject::class
];
public function getNestedConfig(): GridFieldConfig
{
$config = new GridFieldConfig_RecordViewer();
return $config;
}
}
```
You can also modify the default config (a `GridFieldConfig_RecordEditor`) via an extension to the nested model class, by implementing
`updateNestedConfig`, which will get the config object as the first parameter.
```php
class NestedObjectExtension extends DataExtension
{
public function updateNestedConfig(GridFieldConfig &$config)
{
$config->removeComponentsByType(GridFieldPaginator::class);
}
}
```