Permalink
Browse files

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
  • Loading branch information...
1 parent 375ad46 commit 0762be99276e224ae1acc9d2342701bff3c92d15 @chillu chillu committed Mar 5, 2012
Showing with 48 additions and 17 deletions.
  1. +46 −16 forms/gridfield/GridFieldConfig.php
  2. +2 −1 security/Group.php
@@ -105,36 +105,66 @@ public function __construct($itemsPerPage=15) {
}
/**
- * 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_RecordEditor extends GridFieldConfig {
+
+ /**
+ *
+ * @param int $itemsPerPage - How many items per page should show up
+ * @return GridFieldConfig_RecordEditor
+ */
+ public static function create($itemsPerPage=15){
+ return new GridFieldConfig_RecordEditor($itemsPerPage);
+ }
+
+ /**
+ *
+ * @param int $itemsPerPage - How many items per page should show up
+ */
+ 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_ManyManyEditor extends GridFieldConfig {
+class GridFieldConfig_RelationEditor 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_RelationEditor
*/
- public static function create($fieldToSearch, $itemsPerPage=15){
- return new GridFieldConfig_ManyManyEditor($fieldToSearch, $itemsPerPage=15);
+ public static function create($itemsPerPage=15){
+ return new GridFieldConfig_RelationEditor($itemsPerPage=15);
}
/**
*
- * @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 GridFieldRelationAdd());
$this->addComponent(new GridFieldSortableHeader());
$this->addComponent(new GridFieldFilter());
$this->addComponent(new GridFieldDefaultColumns());
View
@@ -63,9 +63,10 @@ public function getCMSFields() {
$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')

0 comments on commit 0762be9

Please sign in to comment.