2016-08-19 10:51:35 +12:00
|
|
|
<?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
|
|
|
|
{
|
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
/**
|
|
|
|
* @param int $itemsPerPage - How many items per page should show up
|
|
|
|
*/
|
|
|
|
public function __construct($itemsPerPage = null)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
$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));
|
2018-05-29 16:10:52 +12:00
|
|
|
$this->addComponent(new GridField_ActionMenu());
|
2016-11-29 12:31:16 +13:00
|
|
|
$this->addComponent(new GridFieldPageCount('toolbar-header-right'));
|
|
|
|
$this->addComponent($pagination = new GridFieldPaginator($itemsPerPage));
|
|
|
|
$this->addComponent(new GridFieldDetailForm());
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
$sort->setThrowExceptionOnBadDataType(false);
|
|
|
|
$filter->setThrowExceptionOnBadDataType(false);
|
|
|
|
$pagination->setThrowExceptionOnBadDataType(false);
|
2016-08-19 10:51:35 +12:00
|
|
|
|
2016-11-29 12:31:16 +13:00
|
|
|
$this->extend('updateConfig');
|
|
|
|
}
|
2016-08-19 10:51:35 +12:00
|
|
|
}
|