Jump to:

23455 Posts in 18904 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Accessing gridfieldconfig in modeladmin

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1206 Views
  • BlueO
    Avatar
    Community Member
    52 Posts

    Accessing gridfieldconfig in modeladmin Link to this post

    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

  • martimiz
    Avatar
    Forum Moderator
    1078 Posts

    Re: Accessing gridfieldconfig in modeladmin Link to this post

    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 { ... }

  • BlueO
    Avatar
    Community Member
    52 Posts

    Re: Accessing gridfieldconfig in modeladmin Link to this post

    Hey great, thanks I'll give it a shot and post back

  • Blackdog
    Avatar
    Community Member
    156 Posts

    Re: Accessing gridfieldconfig in modeladmin Link to this post

    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);
    }
    }

    1206 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.