silverstripe-framework/src/Forms/GridField/GridFieldConfig_RelationEditor.php
Luke Edwards 385e9e105c Create GridField Actions Menu component (#8083)
* WIP GridField action menu work, the gist of the idea is using a new gridfield component

* Add delete action to actions menu

* Actions are added automatically to action menu (allows for extension)

* Add test and minor changes

* Add docs and minor changes

* Refactor ActionMenuItem into distinct types, general ActionMenu cleanup

* Add icons and fix title

* Pass columnName, so it can be used by components

* Update test to open and find action menu buttons

* Add section in changelog upgrade section for GridField_ActionMenu
2018-05-29 16:10:52 +12:00

53 lines
2.0 KiB
PHP

<?php
namespace SilverStripe\Forms\GridField;
/**
* Similar to {@link GridFieldConfig_RecordEditor}, but adds features to work
* on has-many or many-many relationships.
*
* Allows to search for existing records to add to the relationship, detach
* listed records from the relationship (rather than removing them from the
* database), and automatically add newly created records to it.
*
* To further configure the field, use {@link getComponentByType()}, for
* example to change the field to search.
*
* <code>
* GridFieldConfig_RelationEditor::create()
* ->getComponentByType('GridFieldAddExistingAutocompleter')
* ->setSearchFields('MyField');
* </code>
*/
class GridFieldConfig_RelationEditor extends GridFieldConfig
{
/**
* @param int $itemsPerPage - How many items per page should show up
*/
public function __construct($itemsPerPage = null)
{
parent::__construct();
$this->addComponent(new GridFieldButtonRow('before'));
$this->addComponent(new GridFieldAddNewButton('buttons-before-left'));
$this->addComponent(new GridFieldAddExistingAutocompleter('buttons-before-right'));
$this->addComponent(new GridFieldToolbarHeader());
$this->addComponent($sort = new GridFieldSortableHeader());
$this->addComponent($filter = new GridFieldFilterHeader());
$this->addComponent(new GridFieldDataColumns());
$this->addComponent(new GridFieldEditButton());
$this->addComponent(new GridFieldDeleteAction(true));
$this->addComponent(new GridField_ActionMenu());
$this->addComponent(new GridFieldPageCount('toolbar-header-right'));
$this->addComponent($pagination = new GridFieldPaginator($itemsPerPage));
$this->addComponent(new GridFieldDetailForm());
$sort->setThrowExceptionOnBadDataType(false);
$filter->setThrowExceptionOnBadDataType(false);
$pagination->setThrowExceptionOnBadDataType(false);
$this->extend('updateConfig');
}
}