2019-11-18 05:58:33 +01:00
|
|
|
---
|
|
|
|
title: Extending an existing ModelAdmin
|
|
|
|
summary: ModelAdmin interfaces that come with the core can be customised easily
|
|
|
|
---
|
2014-11-07 20:43:57 +01:00
|
|
|
## Extending existing ModelAdmin
|
|
|
|
|
2016-03-30 02:17:28 +02:00
|
|
|
Sometimes you'll work with ModelAdmins from other modules. To customise these interfaces, you can always subclass. But there's
|
2017-07-03 03:22:12 +02:00
|
|
|
also another tool at your disposal: The [Extension](api:SilverStripe\Core\Extension) API.
|
2014-11-07 20:43:57 +01:00
|
|
|
|
2017-08-03 02:51:32 +02:00
|
|
|
|
|
|
|
```php
|
2017-10-27 04:38:27 +02:00
|
|
|
use SilverStripe\Core\Extension;
|
2017-08-07 05:11:17 +02:00
|
|
|
|
2017-10-27 04:38:27 +02:00
|
|
|
class MyAdminExtension extends Extension
|
|
|
|
{
|
|
|
|
// ...
|
|
|
|
public function updateEditForm(&$form)
|
2017-08-07 05:11:17 +02:00
|
|
|
{
|
2017-10-27 04:38:27 +02:00
|
|
|
$form->Fields()->push(/* ... */)
|
2017-08-07 05:11:17 +02:00
|
|
|
}
|
2017-10-27 04:38:27 +02:00
|
|
|
}
|
2017-08-03 02:51:32 +02:00
|
|
|
```
|
2014-11-07 20:43:57 +01:00
|
|
|
|
|
|
|
Now enable this extension through your `[config.yml](/topics/configuration)` file.
|
|
|
|
|
2017-08-03 02:51:32 +02:00
|
|
|
|
|
|
|
```yml
|
2017-10-27 04:38:27 +02:00
|
|
|
MyAdmin:
|
|
|
|
extensions:
|
|
|
|
- MyAdminExtension
|
2017-08-03 02:51:32 +02:00
|
|
|
```
|
2014-11-07 20:43:57 +01:00
|
|
|
|
|
|
|
The following extension points are available: `updateEditForm()`, `updateSearchContext()`,
|
2016-02-17 22:21:59 +01:00
|
|
|
`updateSearchForm()`, `updateList()`, `updateImportForm`.
|