mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT Renamed GridFieldConfig_ManyManyEditor to GridFieldConfig_RelationEditor, to be more in line with underlying component naming, and more accurate (as it allows editing has_many relations as well). Removed $fieldToSearch argument from its constructor to keep config API consistent, should use getComponentByType() for configuration. Added GridFieldConfig_RecordEditor
This commit is contained in:
parent
375ad464db
commit
0762be9927
@ -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.
|
||||
* <code>
|
||||
* GridFieldConfig_RelationEditor::create()
|
||||
* ->getComponentByType('GridFieldRelationAdd')->setSearchFields('MyField');
|
||||
* </code>
|
||||
*/
|
||||
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());
|
||||
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user