From 0952df49fb61399bc23e1bfbc86682e059b11f1f Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Mon, 28 May 2012 11:55:43 +1200 Subject: [PATCH] ENHANCEMENT Allow calling setButtonName() on a GridFieldAddNewButton to customise the button name --- forms/gridfield/GridFieldAddNewButton.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/forms/gridfield/GridFieldAddNewButton.php b/forms/gridfield/GridFieldAddNewButton.php index 61e135549..2086b5a5b 100644 --- a/forms/gridfield/GridFieldAddNewButton.php +++ b/forms/gridfield/GridFieldAddNewButton.php @@ -6,17 +6,31 @@ * @subpackage gridfield */ class GridFieldAddNewButton implements GridField_HTMLProvider { + protected $targetFragment; - + + protected $buttonName; + + public function setButtonName($name) { + $this->buttonName = $name; + return $this; + } + public function __construct($targetFragment = 'before') { $this->targetFragment = $targetFragment; } - + 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( 'NewLink' => Controller::join_links($gridField->Link('item'), 'new'), - 'ButtonName' => _t('GridField.Add', 'Add {name}', array('name' => $gridField->getModelClass())), + 'ButtonName' => $this->buttonName, )); + return array( $this->targetFragment => $data->renderWith('GridFieldAddNewbutton'), );