MultiClassSelector::getHTMLFragments()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
c 0
b 0
f 0
rs 8.8571
cc 3
eloc 16
nc 3
nop 1
1
<?php
2
3
class MultiClassSelector extends GridFieldAddNewMultiClass {
4
	private static $allowed_actions = array(
0 ignored issues
show
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
5
		'handleAdd'
6
	);
7
8
	// Should we add an empty string to the add class dropdown?
9
	private static $showEmptyString = true;
0 ignored issues
show
Unused Code introduced by
The property $showEmptyString is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
11
	private $fragment;
0 ignored issues
show
Unused Code introduced by
The property $fragment is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
13
	private $title;
0 ignored issues
show
Unused Code introduced by
The property $title is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
14
15
	private $classes;
0 ignored issues
show
Unused Code introduced by
The property $classes is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
17
	private $defaultClass;
18
19
20
	public function getHTMLFragments($grid) {
21
		$classes = $this->getClasses($grid);
22
23
		if(!count($classes)) {
24
			return array();
25
		}
26
27
		GridFieldExtensions::include_requirements();
28
29
		$field = new DropdownField(sprintf('%s[ClassName]', __CLASS__), '', $classes, $this->defaultClass);
30
		$field->setAttribute('id', uniqid());
31
		if (Config::inst()->get('GridFieldAddNewMultiClass', 'showEmptyString')) {
32
			$field->setEmptyString(_t('GridFieldExtensions.SELECTTYPETOCREATE', '(Select type to create)'));
33
		}
34
		$field->addExtraClass('no-change-track');
35
36
		$data = new ArrayData(array(
37
			'Title'      => $this->getTitle(),
38
			'Link'       => Controller::join_links($grid->Link(), 'add-multi-class', '{class}'),
39
			'ClassField' => $field
40
		));
41
42
		return array(
43
			$this->getFragment() => $data->renderWith('GridFieldAddNewMultiClass')
44
		);
45
	}
46
}