|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SheaDawson\Blocks\controllers; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Admin\ModelAdmin; |
|
6
|
|
|
use SilverStripe\ORM\Versioning\Versioned; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* BlockAdmin. |
|
10
|
|
|
* |
|
11
|
|
|
* @author Shea Dawson <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class BlockAdmin extends ModelAdmin |
|
14
|
|
|
{ |
|
15
|
|
|
private static $managed_models = array( |
|
|
|
|
|
|
16
|
|
|
"SheaDawson\Blocks\model\Block", |
|
17
|
|
|
"SheaDawson\Blocks\model\BlockSet", |
|
18
|
|
|
); |
|
19
|
|
|
|
|
20
|
|
|
private static $url_segment = "block-admin"; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
private static $menu_title = "Blocks"; |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
public $showImportForm = false; |
|
25
|
|
|
|
|
26
|
|
|
private static $dependencies = array( |
|
|
|
|
|
|
27
|
|
|
"blockManager" => '%$SheaDawson\\Blocks\\BlockManager', |
|
28
|
|
|
); |
|
29
|
|
|
|
|
30
|
|
|
public $blockManager; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return array |
|
34
|
|
|
**/ |
|
35
|
|
|
public function getManagedModels() |
|
36
|
|
|
{ |
|
37
|
|
|
$models = parent::getManagedModels(); |
|
38
|
|
|
|
|
39
|
|
|
// remove blocksets if not in use (set in config): |
|
40
|
|
|
if (!$this->blockManager->getUseBlockSets()) { |
|
41
|
|
|
unset($models['BlockSet']); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return $models; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return Form |
|
49
|
|
|
**/ |
|
50
|
|
|
public function getEditForm($id = null, $fields = null) |
|
51
|
|
|
{ |
|
52
|
|
|
// Versioned::reading_stage('Stage'); |
|
|
|
|
|
|
53
|
|
|
$form = parent::getEditForm($id, $fields); |
|
54
|
|
|
|
|
55
|
|
|
if ($blockGridField = $form->Fields()->fieldByName('Block')) { |
|
56
|
|
|
$blockGridField->setConfig(GridFieldConfig_BlockManager::create(true, true, false)); |
|
57
|
|
|
$config = $blockGridField->getConfig(); |
|
58
|
|
|
$dcols = $config->getComponentByType('GridFieldDataColumns'); |
|
59
|
|
|
$dfields = $dcols->getDisplayFields($blockGridField); |
|
60
|
|
|
unset($dfields['BlockArea']); |
|
61
|
|
|
$dcols->setDisplayFields($dfields); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $form; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getSearchContext() |
|
68
|
|
|
{ |
|
69
|
|
|
$context = parent::getSearchContext(); |
|
70
|
|
|
$fields = $context->getFields(); |
|
71
|
|
|
$subclasses = $this->blockManager->getBlockClasses(); |
|
72
|
|
|
if ($fields->dataFieldByName('q[ClassName]') && sizeof($subclasses) > 1) { |
|
73
|
|
|
$fields->dataFieldByName('q[ClassName]')->setSource($subclasses); |
|
74
|
|
|
$fields->dataFieldByName('q[ClassName]')->setEmptyString('(any)'); |
|
75
|
|
|
} else { |
|
76
|
|
|
$fields->removeByName('q[ClassName]'); |
|
77
|
|
|
} |
|
78
|
|
|
return $context; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.