Skip to content

Commit

Permalink
Block type filter to be compatible with SilverStripe 4.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
waiyanheincyberduck committed Dec 2, 2019
1 parent 368118b commit bb4f3c2
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .idea/Silverstripe-Block-Page.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

201 changes: 201 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/Admin/BlockAdmin.php
Expand Up @@ -22,4 +22,16 @@ public function getEditForm($id = null, $fields = null)

return $form;
}

public function getList()
{
$list = parent::getList();
$requestFilters = $this->getRequest()->requestVar('filter');
$filters = [];
if (isset($requestFilters['CyberDuck-BlockPage-Model-ContentBlock']['ClassName']) and ! empty($requestFilters['CyberDuck-BlockPage-Model-ContentBlock']['ClassName'])) {
$filters['ClassName'] = $requestFilters['CyberDuck-BlockPage-Model-ContentBlock']['ClassName'];
}

return $list->filter($filters);
}
}
16 changes: 14 additions & 2 deletions src/Model/ContentBlock.php
Expand Up @@ -5,6 +5,7 @@
use Page;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
Expand Down Expand Up @@ -48,12 +49,23 @@ class ContentBlock extends DataObject implements PermissionProvider

private static $summary_fields = [
'Thumbnail' => '',
'ID' => 'ID',
'BlockType' => 'Content type',
'ID' => 'ID',
'ClassName' => 'Content type',
'Title' => 'Title',
'Pages.Count' => 'Pages'
];

public function searchableFields()
{
return [
'BlockType' => [
'filter' => 'ExactMatchFilter',
'title' => 'Content Type',
'field' => DropdownField::create('ClassName')->setSource(ContentBlock::get()->map('ClassName', 'ClassName'))->setEmptyString('-- Content Type --')
]
];
}

public function getThumbnail()
{
return DBField::create_field('HTMLText', sprintf('<img src="%s" height="20">', $this->config()->get('preview')));
Expand Down

0 comments on commit bb4f3c2

Please sign in to comment.