mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #493 from halkyon/addnew_button_name
ENHANCEMENT Allow calling setButtonName() on a GridFieldAddNewButton to ...
This commit is contained in:
commit
881c186f6d
@ -6,17 +6,31 @@
|
|||||||
* @subpackage gridfield
|
* @subpackage gridfield
|
||||||
*/
|
*/
|
||||||
class GridFieldAddNewButton implements GridField_HTMLProvider {
|
class GridFieldAddNewButton implements GridField_HTMLProvider {
|
||||||
|
|
||||||
protected $targetFragment;
|
protected $targetFragment;
|
||||||
|
|
||||||
|
protected $buttonName;
|
||||||
|
|
||||||
|
public function setButtonName($name) {
|
||||||
|
$this->buttonName = $name;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct($targetFragment = 'before') {
|
public function __construct($targetFragment = 'before') {
|
||||||
$this->targetFragment = $targetFragment;
|
$this->targetFragment = $targetFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHTMLFragments($gridField) {
|
public function getHTMLFragments($gridField) {
|
||||||
|
if(!$this->buttonName) {
|
||||||
|
// provide a default button name, can be changed by calling {@link setButtonName()} on this component
|
||||||
|
$this->buttonName = _t('GridField.Add', 'Add {name}', array('name' => $gridField->getModelClass()));
|
||||||
|
}
|
||||||
|
|
||||||
$data = new ArrayData(array(
|
$data = new ArrayData(array(
|
||||||
'NewLink' => Controller::join_links($gridField->Link('item'), 'new'),
|
'NewLink' => Controller::join_links($gridField->Link('item'), 'new'),
|
||||||
'ButtonName' => _t('GridField.Add', 'Add {name}', array('name' => $gridField->getModelClass())),
|
'ButtonName' => $this->buttonName,
|
||||||
));
|
));
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
$this->targetFragment => $data->renderWith('GridFieldAddNewbutton'),
|
$this->targetFragment => $data->renderWith('GridFieldAddNewbutton'),
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user