2012-03-09 04:50:43 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This component provides a button for opening the add new form provided by {@link GridFieldDetailForm}.
|
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2012-03-09 04:50:43 +01:00
|
|
|
* @subpackage gridfield
|
|
|
|
*/
|
|
|
|
class GridFieldAddNewButton implements GridField_HTMLProvider {
|
2012-05-28 01:55:43 +02:00
|
|
|
|
2012-03-09 04:50:43 +01:00
|
|
|
protected $targetFragment;
|
2012-05-28 01:55:43 +02:00
|
|
|
|
|
|
|
protected $buttonName;
|
|
|
|
|
|
|
|
public function setButtonName($name) {
|
|
|
|
$this->buttonName = $name;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-03-09 04:50:43 +01:00
|
|
|
public function __construct($targetFragment = 'before') {
|
|
|
|
$this->targetFragment = $targetFragment;
|
|
|
|
}
|
2012-05-28 01:55:43 +02:00
|
|
|
|
2012-03-09 04:50:43 +01:00
|
|
|
public function getHTMLFragments($gridField) {
|
2012-05-28 01:55:43 +02:00
|
|
|
if(!$this->buttonName) {
|
|
|
|
// provide a default button name, can be changed by calling {@link setButtonName()} on this component
|
2012-05-29 15:22:28 +02:00
|
|
|
$this->buttonName = _t('GridField.Add', 'Add {name}', array('name' => singleton($gridField->getModelClass())->singular_name()));
|
2012-05-28 01:55:43 +02:00
|
|
|
}
|
|
|
|
|
2012-03-09 04:50:43 +01:00
|
|
|
$data = new ArrayData(array(
|
|
|
|
'NewLink' => Controller::join_links($gridField->Link('item'), 'new'),
|
2012-05-28 01:55:43 +02:00
|
|
|
'ButtonName' => $this->buttonName,
|
2012-03-09 04:50:43 +01:00
|
|
|
));
|
2012-05-28 01:55:43 +02:00
|
|
|
|
2012-03-09 04:50:43 +01:00
|
|
|
return array(
|
|
|
|
$this->targetFragment => $data->renderWith('GridFieldAddNewbutton'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|