diff --git a/src/Forms/GridField/GridFieldAddByDBField.php b/src/Forms/GridField/GridFieldAddByDBField.php index 6c4e73b..43a0c43 100644 --- a/src/Forms/GridField/GridFieldAddByDBField.php +++ b/src/Forms/GridField/GridFieldAddByDBField.php @@ -37,6 +37,13 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP */ protected $dataObjectField = 'Title'; + /** + * Name for the buttons displayed in the CMS + * + * @var string + */ + protected $buttonName; + /** * Creates a text field and add button which allows the user to directly create a new * DataObject by just entering the title. @@ -142,6 +149,19 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP return $this->dataObjectField; } + /** + * Set the button name + * + * @param $name string + * @return $this + */ + public function setButtonName($name) + { + $this->buttonName = $name; + + return $this; + } + /** * Set the database field. * @@ -188,6 +208,12 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP ->setAttribute('placeholder', $obj->fieldLabel($dbField)) ->addExtraClass('no-change-track'); + if (!$this->buttonName) { + // provide a default button name, can be changed by calling {@link setButtonName()} on this component + $objectName = $obj->i18n_singular_name(); + $this->buttonName = _t(__CLASS__ . '.ButtonName', '{name}', ['name' => $objectName]); + } + $addAction = GridField_FormAction::create( $gridField, 'add', @@ -195,7 +221,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP __CLASS__ . '.Add', 'Add {name}', 'Add button text', - ['name' => $obj->i18n_singular_name()] + ['name' => $this->buttonName] ), 'add', 'add'