21278 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 565 Views |
-
Accessing gridfieldconfig in modeladmin

5 July 2012 at 6:49pm
Hi there,
I'm trying to customise the gridfield that Model admin uses to manage dataobjects. I know i can use searchable_fields and summaray_fields etc to customise it a bit. Would anyone know how would I go about accessing the gridfieldconfig to add gridfield components?
cheers
Bernard
-
Re: Accessing gridfieldconfig in modeladmin

5 July 2012 at 11:48pm
The GridField is created in ModelAdmin->getEditForm(). This function does it all: create the config, create the field and then create and return the Form that holds the field. There doesn't seem to be an easy way to 'intercept' the creation of the config. The getEditForm function can be decorated - but from there you'll have to access the form already created - so you might be able to do something like this (if by chance I understand it correctly):
// suppose the DataObject involved is called 'MyDataObject'
$form->dataFieldByName('MyDataObject')->getConfig()->addComponent($someComponent);Or (faster, maybe less complex but just not as nice) copy the entire function to your class MyDataObject_Admin extends ModelAdmin { ... }
-
Re: Accessing gridfieldconfig in modeladmin

6 July 2012 at 4:22pm
Hey great, thanks I'll give it a shot and post back
-
Re: Accessing gridfieldconfig in modeladmin

20 July 2012 at 1:41am
If anyone comes across the issue they can use this code.
$form->Fields()->fieldByName('YourFieldName')->getConfig()->addComponent($Component);
As dataFieldByName has been deprecated in 3.0
I suggest you use the Extension api and build a quick extension for updateEditForm rather than duplicate the function from ModelAdmin.
class YourExtension extends Extension
{
function updateEditForm(&$form)
{
$form->Fields()->fieldByName('YourField')->getConfig()->addComponent($Component);
}
}
| 565 Views | ||
|
Page:
1
|
Go to Top |

