/
FolderField.php
67 lines (57 loc) · 1.74 KB
/
FolderField.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Concrete\Core\File\Search\Field\Field;
use Concrete\Core\File\FileList;
use Concrete\Core\File\FolderItemList;
use Concrete\Core\File\Set\Set;
use Concrete\Core\File\Type\Type;
use Concrete\Core\Search\Field\AbstractField;
use Concrete\Core\Search\Field\FieldInterface;
use Concrete\Core\Search\ItemList\ItemList;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\Tree\Node\Node;
use Concrete\Core\Tree\Node\Type\FileFolder;
use Concrete\Core\User\User;
class FolderField extends AbstractField
{
public function __construct(FileFolder $folder = null, $searchSubFolders = false)
{
if ($folder) {
$this->data['folderID'] = $folder->getTreeNodeID();
$this->data['searchSubFolder'] = $searchSubFolders;
$this->isLoaded = true;
}
}
protected $requestVariables = [
'folderID',
];
public function getKey()
{
return 'folder';
}
public function getDisplayName()
{
return t('Folder');
}
/**
* @param FolderItemList $list
* @param $request
*/
public function filterList(ItemList $list)
{
$folderID = $this->getData('folderID');
if ($folderID) {
$folder = Node::getByID($folderID);
if ($folder && $folder instanceof FileFolder) {
$list->filterByParentFolder($folder);
if ($this->getData('searchSubFolder')) {
$list->enableSubFolderSearch();
}
}
}
}
public function renderSearchField()
{
$selector = new \Concrete\Core\Form\Service\Widget\FileFolderSelector();
return $selector->selectFileFolder('folderID', $this->getData('folderID'), false);
}
}