Merge pull request #590 from Rhym/feature/gridfield-add-button-name

Feature/gridfield add button name
This commit is contained in:
Dylan Wagstaff 2019-07-12 09:59:20 +12:00 committed by GitHub
commit 3c5b2b64ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 1 deletions

View File

@ -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'