src/Models/ApiObject.php
protected function makeRecordViewer($fields, $name, $relation, $viewComponent = 'Firebrand\Hail\Forms\GridFieldViewButton')
    {
        $config = GridFieldConfig_RecordViewer::create();

        // Remove the standard GridFieldView button and replace it with our
        // custom button that will link to our the right action in our HailModelAdmin
        $config->removeComponentsByType('SilverStripe\Forms\GridField\GridFieldViewButton');
        $config->addComponents(new $viewComponent());

        //Relation tab names don't have spaces in SS4
        $tab_name = str_replace(" ", "", $name);
        $grid = new GridFieldForReadonly($tab_name, $name, $relation, $config);
        $fields->addFieldToTab('Root.' . $tab_name, $grid);
    }
protected function makeRecordViewer($fields, $name, $relation, $viewComponent = 'Firebrand\Hail\Forms\GridFieldViewButton')
    {
        $config = GridFieldConfig_RecordViewer::create();

        // Remove the standard GridFieldView button and replace it with our
        // custom button that will link to our the right action in our HailModelAdmin
        $config->removeComponentsByType('SilverStripe\Forms\GridField\GridFieldViewButton');
        $config->addComponents(new $viewComponent());

        //Relation tab names don't have spaces in SS4
        $tab_name = str_replace(" ", "", $name);
        $grid = new GridFieldForReadonly($tab_name, $name, $relation, $config);
        $fields->addFieldToTab('Root.' . $tab_name, $grid);
    }
protected function makeRecordViewer ( $ fields , $ name , $ relation , $ viewComponent = 'Firebrand\Hail\Forms\GridFieldViewButton' ) { $ config = GridFieldConfig_RecordViewer :: create ( ) ; // Remove the standard GridFieldView button and replace it with our // custom button that will link to our the right action in our HailModelAdmin $ config -> removeComponentsByType ( 'SilverStripe\Forms\GridField\GridFieldViewButton' ) ; $ config -> addComponents ( new $ viewComponent ( ) ) ; //Relation tab names don't have spaces in SS4 $ tab_name = str_replace ( " " , "" , $ name ) ; $ grid = new GridFieldForReadonly ( $ tab_name , $ name , $ relation , $ config ) ; $ fields -> addFieldToTab ( 'Root.' . $ tab_name , $ grid ) ; }
Helper function to add a ReadOnly gridfield for a relation

@param FieldList $fields
@param string $name Name that should be given to the GridField
@param ManyManyList $relation Relation to display
@param string $viewComponent Full class name of the view Component to add (button)
Helper function to add a ReadOnly gridfield for a relation