Skip to content

Commit

Permalink
feat(gridfield): Open all elements by default, unless they have stati…
Browse files Browse the repository at this point in the history
…c $default_is_open set to false
  • Loading branch information
Marco Crespi committed Feb 22, 2018
1 parent d60cf26 commit e5a13f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions code/GridFieldPageSectionsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ public function augmentColumns($gridField, &$columns) {
$state = $gridField->getState();
if (!isset($state->open)) {
$state->open = array();

// Open all elements by default
$list = array();
$newList = $gridField->getManipulatedList();
while (count($list) < count($newList)) {
foreach ($newList as $item) {
if ($item->isOpenByDefault()) {
$this->openElement($state, $item);
}
}
$list = $newList;
$newList = $gridField->getManipulatedList();
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions code/PageElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
class PageElement extends DataObject {
public static $singular_name = 'Element';
public static $plural_name = 'Elements';
public static $default_is_open = true;
public function getSingularName() { return static::$singular_name; }
public function getPluralName() { return static::$plural_name; }
public function isOpenByDefault() { return static::$default_is_open; }

function canView($member = null) { return true; }
function canEdit($member = null) { return true; }
Expand Down

0 comments on commit e5a13f3

Please sign in to comment.