0
votes

I'd like to do a number of small customizations on the ModelAdmin.

  1. I'd like to change the text on the 'Add' button to one that is different from the original DataModel.

  2. I have a has_many relationship. I'd like to hide the ability to 'link to existing' so that one cannot search for other 'skills' as per below.

I have the following in the Model:

public function getCMSFields() {

    ...

    $characterSkillsField = new GridField(
                'CharacterSkills',
                'Character Skills',
                $this->CharacterSkills(),
                GridFieldConfig_RelationEditor::create()
            );

    $fields->addFieldToTab('Root.CharacterSkills', $characterSkillsField);

    ...

}

ANSWER to #2:

// Add the relation editor.

$config = GridFieldConfig_RelationEditor::create();

// Remove the ability to search and link to other skills.

$config->removeComponentsByType('GridFieldAddExistingAutocompleter');

$characterSkillsField = new GridField( 'CharacterSkills', 'Character Skills', $this->CharacterSkills(), $config );

1

1 Answers

4
votes

regarding #1:

add the following to the model class that's managed by the GridField (e.g. 'CharacterSkill') :

private static $singular_name = 'foo';
private static $plural_name = 'bar';

don't forget flushing the cache afterwards (add '?flush=All' to the url).

the preceding will set the button name to 'Add foo', but it's also possible to set your very own button title, using the following:

$config = GridFieldConfig_RelationEditor::create();
$addButton = $config->getComponentByType('GridFieldAddNewButton');
$addButton->setButtonName('my button name');