silverstripe-framework/src/Forms/GridField/GridFieldButtonRow.php
GuySartorelli 5c54276b6f
ENH Make all GridField components injectable (using abstract class) (#10204)
* ENH Make all GridField components injectable.

Some components were already injectable, but all GridField components shipped in silverstripe should be injectable.
This makes it a LOT easier to make global project-specific changes to a given component.
The new AbstractGridFieldComponent also makes it easy to make similar wide-spread changes in the future.

* DOCS Encourage injection for GridField and GridFieldComponents.
2022-02-02 11:14:33 +13:00

41 lines
1.1 KiB
PHP

<?php
namespace SilverStripe\Forms\GridField;
use SilverStripe\View\ArrayData;
use SilverStripe\View\SSViewer;
/**
* Adding this class to a {@link GridFieldConfig} of a {@link GridField} adds
* a button row to that field.
*
* The button row provides a space for actions on this grid.
*
* This row provides two new HTML fragment spaces: 'toolbar-header-left' and
* 'toolbar-header-right'.
*/
class GridFieldButtonRow extends AbstractGridFieldComponent implements GridField_HTMLProvider
{
protected $targetFragment;
public function __construct($targetFragment = 'before')
{
$this->targetFragment = $targetFragment;
}
public function getHTMLFragments($gridField)
{
$data = new ArrayData([
"TargetFragmentName" => $this->targetFragment,
"LeftFragment" => "\$DefineFragment(buttons-{$this->targetFragment}-left)",
"RightFragment" => "\$DefineFragment(buttons-{$this->targetFragment}-right)",
]);
$templates = SSViewer::get_templates_by_class($this, '', __CLASS__);
return [
$this->targetFragment => $data->renderWith($templates)
];
}
}