protected function modifyGridField(CMSForm $form, GridField $gridField)
    {
        $gridFieldConfig = $gridField->getConfig();

        $gridFieldConfig->removeComponentsByType('GridFieldEditButton');
        $gridFieldConfig->addComponent(new DMSGridFieldEditButton(), 'GridFieldDeleteAction');

        if ($this->modelClass === 'DMSDocument') {
            $gridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
            $gridFieldConfig->addComponent(
                new DMSGridFieldAddNewButton('buttons-before-left'),
                'GridFieldExportButton'
            );
        } elseif ($this->modelClass === 'DMSDocumentSet') {
            $dataColumns = $gridFieldConfig->getComponentByType('GridFieldDataColumns');
            $fields = $dataColumns->getDisplayFields($gridField);
            $fields = array('Title' => 'Title', 'Page.Title' => 'Page') + $fields;
            $dataColumns->setDisplayFields($fields)
                ->setFieldFormatting(
                    array(
                        'Page.Title' => function ($value, $item) {
                            // Link a page click directly to the Document Set on the actual page
                            if ($page = SiteTree::get()->byID($item->PageID)) {
                                return sprintf(
                                    "<a class='dms-doc-sets-link' href='%s/#Root_DocumentSets%s'>$value</a>",
                                    $page->CMSEditLink(),
                                    $page->DocumentSets()->count()
                                );
                            }
                        }
                    )
                );
        }

        return $form;
    }
protected function modifyGridField(CMSForm $form, GridField $gridField)
    {
        $gridFieldConfig = $gridField->getConfig();

        $gridFieldConfig->removeComponentsByType('GridFieldEditButton');
        $gridFieldConfig->addComponent(new DMSGridFieldEditButton(), 'GridFieldDeleteAction');

        if ($this->modelClass === 'DMSDocument') {
            $gridFieldConfig->removeComponentsByType('GridFieldAddNewButton');
            $gridFieldConfig->addComponent(
                new DMSGridFieldAddNewButton('buttons-before-left'),
                'GridFieldExportButton'
            );
        } elseif ($this->modelClass === 'DMSDocumentSet') {
            $dataColumns = $gridFieldConfig->getComponentByType('GridFieldDataColumns');
            $fields = $dataColumns->getDisplayFields($gridField);
            $fields = array('Title' => 'Title', 'Page.Title' => 'Page') + $fields;
            $dataColumns->setDisplayFields($fields)
                ->setFieldFormatting(
                    array(
                        'Page.Title' => function ($value, $item) {
                            // Link a page click directly to the Document Set on the actual page
                            if ($page = SiteTree::get()->byID($item->PageID)) {
                                return sprintf(
                                    "<a class='dms-doc-sets-link' href='%s/#Root_DocumentSets%s'>$value</a>",
                                    $page->CMSEditLink(),
                                    $page->DocumentSets()->count()
                                );
                            }
                        }
                    )
                );
        }

        return $form;
    }
protected function modifyGridField ( CMSForm $ form , GridField $ gridField ) { $ gridFieldConfig = $ gridField -> getConfig ( ) ; $ gridFieldConfig -> removeComponentsByType ( 'GridFieldEditButton' ) ; $ gridFieldConfig -> addComponent ( new DMSGridFieldEditButton ( ) , 'GridFieldDeleteAction' ) ; if ( $ this -> modelClass === 'DMSDocument' ) { $ gridFieldConfig -> removeComponentsByType ( 'GridFieldAddNewButton' ) ; $ gridFieldConfig -> addComponent ( new DMSGridFieldAddNewButton ( 'buttons-before-left' ) , 'GridFieldExportButton' ) ; } elseif ( $ this -> modelClass === 'DMSDocumentSet' ) { $ dataColumns = $ gridFieldConfig -> getComponentByType ( 'GridFieldDataColumns' ) ; $ fields = $ dataColumns -> getDisplayFields ( $ gridField ) ; $ fields = array ( 'Title' => 'Title' , 'Page.Title' => 'Page' ) + $ fields ; $ dataColumns -> setDisplayFields ( $ fields ) -> setFieldFormatting ( array ( 'Page.Title' => function ( $ value , $ item ) { // Link a page click directly to the Document Set on the actual page if ( $ page = SiteTree :: get ( ) -> byID ( $ item -> PageID ) ) { return sprintf ( "<a class='dms-doc-sets-link' href='%s/#Root_DocumentSets%s'>$value</a>" , $ page -> CMSEditLink ( ) , $ page -> DocumentSets ( ) -> count ( ) ) ; } } ) ) ; } return $ form ; }
If the GridField is for DMSDocument then add a custom "add" button. If it's for DMSDocumentSet then
update the display fields to include some extra columns that are only for this ModelAdmin, so cannot
be added directly to the model's display fields.

@param  CMSForm   $form
@param  GridField $gridField
@return CMSForm
If the GridField is for DMSDocument then add a custom add button . If it s for DMSDocumentSet then update the display fields to include some extra columns that are only for this ModelAdmin so cannot be added directly to the model s display fields .