diff --git a/forms/gridfield/GridFieldConfig.php b/forms/gridfield/GridFieldConfig.php index 61d9f4201..9bee380e0 100755 --- a/forms/gridfield/GridFieldConfig.php +++ b/forms/gridfield/GridFieldConfig.php @@ -105,36 +105,66 @@ class GridFieldConfig_Base extends GridFieldConfig { } /** - * This GridFieldConfig bundles a common set of componentes used for displaying - * a gridfield with: - * - * - Relation adding - * - Sortable header - * - Default columns - * - Edit links on every item - * - Action for removing relationship - * - Paginator * */ -class GridFieldConfig_ManyManyEditor extends GridFieldConfig { +class GridFieldConfig_RecordEditor extends GridFieldConfig { /** * - * @param string $fieldToSearch - Which field on the object should be searched for * @param int $itemsPerPage - How many items per page should show up - * @return GridFieldConfig_ManyManyEditor + * @return GridFieldConfig_RecordEditor */ - public static function create($fieldToSearch, $itemsPerPage=15){ - return new GridFieldConfig_ManyManyEditor($fieldToSearch, $itemsPerPage=15); + public static function create($itemsPerPage=15){ + return new GridFieldConfig_RecordEditor($itemsPerPage); } /** * - * @param string $fieldToSearch - Which field on the object should be searched for * @param int $itemsPerPage - How many items per page should show up */ - public function __construct($fieldToSearch, $itemsPerPage=15) { - $this->addComponent(new GridFieldRelationAdd($fieldToSearch)); + public function __construct($itemsPerPage=15) { + $this->addComponent(new GridFieldSortableHeader()); + $this->addComponent(new GridFieldFilter()); + $this->addComponent(new GridFieldDefaultColumns()); + $this->addComponent(new GridFieldAction_Edit()); + $this->addComponent(new GridFieldAction_Delete()); + $this->addComponent(new GridFieldPaginator($itemsPerPage)); + $this->addComponent(new GridFieldPopupForms()); + } +} + + +/** + * 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. + * + * GridFieldConfig_RelationEditor::create() + * ->getComponentByType('GridFieldRelationAdd')->setSearchFields('MyField'); + * + */ +class GridFieldConfig_RelationEditor extends GridFieldConfig { + + /** + * + * @param int $itemsPerPage - How many items per page should show up + * @return GridFieldConfig_RelationEditor + */ + public static function create($itemsPerPage=15){ + return new GridFieldConfig_RelationEditor($itemsPerPage=15); + } + + /** + * + * @param int $itemsPerPage - How many items per page should show up + */ + public function __construct($itemsPerPage=15) { + $this->addComponent(new GridFieldRelationAdd()); $this->addComponent(new GridFieldSortableHeader()); $this->addComponent(new GridFieldFilter()); $this->addComponent(new GridFieldDefaultColumns()); diff --git a/security/Group.php b/security/Group.php index 8925ba472..ffd7f8f4c 100755 --- a/security/Group.php +++ b/security/Group.php @@ -63,9 +63,10 @@ class Group extends DataObject { $config = new GridFieldConfig(); $config->addComponent(new GridFieldTitle()); - $configs = new GridFieldConfig_ManyManyEditor('FirstName', 20); $components = $configs->getComponents(); foreach($components as $component) $config->addComponent($component); + $config = new GridFieldConfig_RelationEditor('FirstName', 20); + $config = new GridFieldConfig_RelationEditor(20); $config->addComponents(new GridFieldExporter()); $config->getComponentByType('GridFieldRelationAdd')