1
|
|
|
<?php use SaltedHerring\Debugger as Debugger; |
2
|
|
|
/** |
3
|
|
|
* @file BlocksAdmin.php |
4
|
|
|
* |
5
|
|
|
* Left-hand-side tab : Admin Blocks |
6
|
|
|
* */ |
7
|
|
|
class BlocksAdmin extends ModelAdmin { |
8
|
|
|
private static $managed_models = array('Block'); |
9
|
|
|
private static $url_segment = 'blocks'; |
10
|
|
|
private static $menu_title = 'Blocks'; |
11
|
|
|
private static $menu_priority = 10; |
12
|
|
|
private static $menu_icon = 'silverstripe-block/images/icon-block.png'; |
13
|
|
|
|
14
|
|
|
public function getEditForm($id = null, $fields = null) { |
15
|
|
|
$form = parent::getEditForm($id, $fields); |
16
|
|
|
|
17
|
|
|
$grid = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass)); |
18
|
|
|
|
19
|
|
|
$grid->getConfig() |
20
|
|
|
->removeComponentsByType('GridFieldPaginator') |
21
|
|
|
->removeComponentsByType('GridFieldAddNewButton') |
22
|
|
|
->removeComponentsByType('GridFieldPrintButton') |
23
|
|
|
->removeComponentsByType('GridFieldExportButton') |
24
|
|
|
->removeComponentsByType('GridFieldDetailForm') |
25
|
|
|
->addComponents( |
26
|
|
|
new VersionedForm(), |
27
|
|
|
new GridFieldPaginatorWithShowAll(30), |
28
|
|
|
$multiClass = new MultiClassSelector(), |
29
|
|
|
$sortable = new GridFieldOrderableRows('SortOrder') |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
$subBlocks = self::getAvaiableTypes(); |
33
|
|
|
$multiClass->setClasses($subBlocks); |
34
|
|
|
$grid->setTitle('All Blcoks'); |
35
|
|
|
return $form; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getList() { |
39
|
|
|
$list = Versioned::get_by_stage('Block', 'Stage'); |
40
|
|
|
|
41
|
|
|
return $list; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public static function getAvaiableTypes() { |
45
|
|
|
$subBlocks = ClassInfo::subclassesFor('Block'); |
46
|
|
|
if (is_null($subBlocks)) { |
47
|
|
|
$subBlocks = array('Block'); |
48
|
|
|
}else{ |
49
|
|
|
$disabledTypes = Config::inst()->get('Block','DisabledBlocks'); |
50
|
|
|
if (!empty($disabledTypes)) { |
51
|
|
|
foreach ($disabledTypes as $disabledType) { |
52
|
|
|
unset($subBlocks[$disabledType]); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
foreach ($subBlocks as $key => &$value) { |
56
|
|
|
$value = empty($key::$singular_name) ? ucwords(trim(strtolower(preg_replace('/_?([A-Z])/', ' $1', $value)))) : $key::$singular_name; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $subBlocks; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|