Completed
Push — master ( cd834b...e038e5 )
by Leo
03:10
created

BlocksAdmin::getEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 22
rs 9.2
cc 1
eloc 16
nc 1
nop 2
1
<?php
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
		
20
		$grid->getConfig()
21
			->removeComponentsByType('GridFieldPaginator')
22
			->removeComponentsByType('GridFieldAddNewButton')
23
			->removeComponentsByType('GridFieldPrintButton')
24
			->removeComponentsByType('GridFieldExportButton')
25
			->addComponents(
26
				new GridFieldPaginatorWithShowAll(30),
27
				$multiClass = new MultiClassSelector(),
28
				$sortable = new GridFieldOrderableRows('SortOrder')
29
			);
30
			
31
		$subBlocks = self::getAvaiableTypes();
32
		$multiClass->setClasses($subBlocks);
33
		$grid->setTitle('All Blcoks');
34
		return $form;
35
	}
36
	
37
	public static function getAvaiableTypes() {
38
		$subBlocks = ClassInfo::subclassesFor('Block');
39
		if (is_null($subBlocks)) {
40
			$subBlocks = array('Block');
41
		}else{
42
			$disabledTypes = Config::inst()->get('Block','DisabledBlocks');
43
			Debugger::inspect($disabledTypes);
44
			if (!empty($disabledTypes)) {
45
				foreach ($disabledTypes as $disabledType) {
46
					unset($subBlocks[$disabledType]);
47
				}
48
			}
49
			foreach ($subBlocks as $key => &$value) {
50
				$value = empty($key::$singular_name) ? ucwords(trim(strtolower(preg_replace('/_?([A-Z])/', ' $1', $value)))) : $key::$singular_name;
51
			}
52
		}
53
		
54
		return $subBlocks;
55
	}
56
}
57