Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,5 @@ $gridConfig->addComponent($limiter);

## To Do

- Setup ability to customize notes.
- Setup the ability to modify the returned list without actually affecting relations (i.e. read only, no writing at all to the database).
- Unit tests to cover current functionality.
43 changes: 43 additions & 0 deletions code/GridFieldConfig_LimitedRecordEditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Sets up a quick GridField configuration for modifying relations using the GridFieldLimitItems component.
*
* @author Patrick Nelson, pat@catchyour.com
*
* @since 2016-02-24
*/
class GridFieldConfig_LimitedRecordEditor extends GridFieldConfig_RecordEditor
{
/**
* Setup new configuration for a relation with a hard maximum limit of items.
*
* @param int $maxItems
*/
public function __construct($maxItems)
{
parent::__construct($maxItems);

// Since GridFieldLimitItems is not yet compatible with GridFieldPaginator, remove that now.
$this->removeComponentsByType('GridFieldPaginator');
$this->removeComponentsByType('GridFieldPageCount');
$this->removeComponentsByType('GridFieldDetailForm');

// Setup GridFieldLimitItems.
$this->addComponent(new GridFieldLimitItems($maxItems));
$this->addComponent(new GridFieldLimitItemsDetailForm());
}

/**
* Changing default 'insertBefore' value to ensure all new components added will run prior to the
* 'GridFieldLimitItems' component.
*
* @param GridFieldComponent $component
* @param string $insertBefore
*
* @return GridFieldConfig_LimitedRelationEditor
*/
public function addComponent(GridFieldComponent $component, $insertBefore = 'GridFieldLimitItems')
{
return parent::addComponent($component, $insertBefore);
}
}
61 changes: 32 additions & 29 deletions code/GridFieldConfig_LimitedRelationEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,41 @@
* Sets up a quick GridField configuration for modifying relations using the GridFieldLimitItems component.
*
* @author Patrick Nelson, pat@catchyour.com
*
* @since 2016-02-24
*/
class GridFieldConfig_LimitedRelationEditor extends GridFieldConfig_RelationEditor
{
/**
* Setup new configuration for a relation with a hard maximum limit of items.
*
* @param int $maxItems
*/
public function __construct($maxItems)
{
parent::__construct($maxItems);

class GridFieldConfig_LimitedRelationEditor extends GridFieldConfig_RelationEditor {

/**
* Setup new configuration for a relation with a hard maximum limit of items.
*
* @param int $maxItems
*/
public function __construct($maxItems) {
parent::__construct($maxItems);

// Since GridFieldLimitItems is not yet compatible with GridFieldPaginator, remove that now.
$this->removeComponentsByType('GridFieldPaginator');
$this->removeComponentsByType('GridFieldPageCount');

// Setup GridFieldLimitItems.
$this->addComponent(new GridFieldLimitItems($maxItems));
}

// Since GridFieldLimitItems is not yet compatible with GridFieldPaginator, remove that now.
$this->removeComponentsByType('GridFieldPaginator');
$this->removeComponentsByType('GridFieldPageCount');
$this->removeComponentsByType('GridFieldDetailForm');

/**
* Changing default 'insertBefore' value to ensure all new components added will run prior to the
* 'GridFieldLimitItems' component.
*
* @param GridFieldComponent $component
* @param string $insertBefore
* @return GridFieldConfig_LimitedRelationEditor
*/
public function addComponent(GridFieldComponent $component, $insertBefore = 'GridFieldLimitItems') {
return parent::addComponent($component, $insertBefore);
}
// Setup GridFieldLimitItems.
$this->addComponent(new GridFieldLimitItems($maxItems));
$this->addComponent(new GridFieldLimitItemsDetailForm());
}

/**
* Changing default 'insertBefore' value to ensure all new components added will run prior to the
* 'GridFieldLimitItems' component.
*
* @param GridFieldComponent $component
* @param string $insertBefore
*
* @return GridFieldConfig_LimitedRelationEditor
*/
public function addComponent(GridFieldComponent $component, $insertBefore = 'GridFieldLimitItems')
{
return parent::addComponent($component, $insertBefore);
}
}
Loading