mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #590 from Rhym/feature/gridfield-add-button-name
Feature/gridfield add button name
This commit is contained in:
commit
3c5b2b64ab
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user