/
ContainsBlockTypeField.php
52 lines (42 loc) · 1.17 KB
/
ContainsBlockTypeField.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Concrete\Core\Page\Search\Field\Field;
use Concrete\Core\Block\BlockType\BlockType;
use Concrete\Core\Block\BlockType\BlockTypeList;
use Concrete\Core\File\FileList;
use Concrete\Core\Search\Field\AbstractField;
use Concrete\Core\Search\ItemList\ItemList;
class ContainsBlockTypeField extends AbstractField
{
protected $requestVariables = [
'btID'
];
public function getKey()
{
return 'contains_block_type';
}
public function getDisplayName()
{
return t('Contains Block Type');
}
/**
* @param FileList $list
* @param $request
*/
public function filterList(ItemList $list)
{
$bt = BlockType::getByID($this->getData('btID'));
$list->filterByBlockType($bt);
}
public function renderSearchField()
{
$form = \Core::make('helper/form');
$list = new BlockTypeList();
$html = $form->select('btID', array_reduce(
$list->get(), function ($types, $type) {
$types[$type->getBlockTypeID()] = $type->getBlockTypeName();
return $types;
}
), $this->getData('btID'));
return $html;
}
}