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';
|
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
|
* Creates a text field and add button which allows the user to directly create a new
|
||||||
* DataObject by just entering the title.
|
* DataObject by just entering the title.
|
||||||
|
@ -142,6 +149,19 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
||||||
return $this->dataObjectField;
|
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.
|
* Set the database field.
|
||||||
*
|
*
|
||||||
|
@ -188,6 +208,12 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
||||||
->setAttribute('placeholder', $obj->fieldLabel($dbField))
|
->setAttribute('placeholder', $obj->fieldLabel($dbField))
|
||||||
->addExtraClass('no-change-track');
|
->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(
|
$addAction = GridField_FormAction::create(
|
||||||
$gridField,
|
$gridField,
|
||||||
'add',
|
'add',
|
||||||
|
@ -195,7 +221,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
|
||||||
__CLASS__ . '.Add',
|
__CLASS__ . '.Add',
|
||||||
'Add {name}',
|
'Add {name}',
|
||||||
'Add button text',
|
'Add button text',
|
||||||
['name' => $obj->i18n_singular_name()]
|
['name' => $this->buttonName]
|
||||||
),
|
),
|
||||||
'add',
|
'add',
|
||||||
'add'
|
'add'
|
||||||
|
|
Loading…
Reference in New Issue