Passed
Push — master ( d7fd6a...9124ff )
by Robbie
11:58
created

BaseHomePage   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
dl 0
loc 126
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getCMSFields() 0 89 1
A Quicklinks() 0 2 1
1
<?php
2
/**
3
 * **BaseHomePage** is the basic home page.
4
 * By default it is hidden from the CMS - we rely on developers creating their own
5
 * `HomePage` class in the `mysite/code` which will extend from the **BaseHomePage**.
6
 */
7
8
class BaseHomePage extends Page {
0 ignored issues
show
Bug introduced by
The type Page was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
	private static $icon = 'cwp/images/icons/sitetree_images/home.png';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
11
12
	private static $hide_ancestor = 'BaseHomePage';
0 ignored issues
show
introduced by
The private property $hide_ancestor is not used, and could be removed.
Loading history...
13
14
	private static $singular_name = 'Home Page';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
15
16
	private static $plural_name = 'Home Pages';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
17
18
	private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
19
		'FeatureOneTitle' => 'Varchar(255)',
20
		'FeatureOneCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')",
21
		'FeatureOneContent' => 'HTMLText',
22
		'FeatureOneButtonText' => 'Varchar(255)',
23
		'FeatureTwoTitle' => 'Varchar(255)',
24
		'FeatureTwoCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')",
25
		'FeatureTwoContent' => 'HTMLText',
26
		'FeatureTwoButtonText' => 'Varchar(255)'
27
	);
28
29
	private static $has_one = array(
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
30
		'LearnMorePage' => 'SiteTree',
31
		'FeatureOneLink' => 'SiteTree',
32
		'FeatureTwoLink' => 'SiteTree'
33
	);
34
35
	private static $has_many = array(
0 ignored issues
show
introduced by
The private property $has_many is not used, and could be removed.
Loading history...
36
		'Quicklinks' => 'Quicklink.Parent'
37
	);
38
39
	public $pageIcon = 'images/icons/sitetree_images/home.png';
40
41
	public function Quicklinks() {
42
		return $this->getComponents('Quicklinks')->sort('SortOrder');
43
	}
44
45
	public function getCMSFields() {
46
		$this->beforeUpdateCMSFields(function (FieldList $fields) {
47
			// Main Content tab
48
			$fields->addFieldToTab(
49
				'Root.Main',
50
				TreeDropdownField::create(
51
					'LearnMorePageID',
52
					_t('BaseHomePage.LearnMoreLink','Page to link the "Learn More" button to:'),
53
					'SiteTree'
54
				),
55
				'Metadata'
56
			);
57
58
			$gridField = GridField::create(
59
				'Quicklinks',
60
				'Quicklinks',
61
				$this->Quicklinks(),
62
				GridFieldConfig_RelationEditor::create()
63
			);
64
			$gridConfig = $gridField->getConfig();
65
			$gridConfig->getComponentByType('GridFieldAddNewButton')->setButtonName(
0 ignored issues
show
Bug introduced by
The method setButtonName() does not exist on GridFieldComponent. It seems like you code against a sub-type of GridFieldComponent such as GridField_URLHandlerTest_Component or GridFieldLevelup or GridFieldAddNewButton. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
			$gridConfig->getComponentByType('GridFieldAddNewButton')->/** @scrutinizer ignore-call */ setButtonName(
Loading history...
66
				_t('BaseHomePage.AddNewButton','Add new')
67
			);
68
			$gridConfig->removeComponentsByType('GridFieldAddExistingAutocompleter');
69
			$gridConfig->removeComponentsByType('GridFieldDeleteAction');
70
			$gridConfig->addComponent(new GridFieldDeleteAction());
71
			$gridConfig->addComponent(new GridFieldSortableRows('SortOrder'));
0 ignored issues
show
Bug introduced by
The type GridFieldSortableRows was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
			$gridField->setModelClass('Quicklink');
73
74
			$fields->addFieldToTab('Root.Quicklinks', $gridField);
75
76
			$fields->removeByName('Import');
77
78
			$fields->addFieldToTab(
79
				'Root.Features',
80
				ToggleCompositeField::create('FeatureOne', _t('SiteTree.FeatureOne', 'Feature One'),
81
					array(
82
						TextField::create('FeatureOneTitle', _t('BaseHomePage.Title','Title')),
83
						$dropdownField = DropdownField::create(
84
							'FeatureOneCategory',
85
							_t('BaseHomePage.FeatureCategoryDropdown','Category icon'),
86
							singleton('BaseHomePage')->dbObject('FeatureOneCategory')->enumValues()
87
						),
88
						HTMLEditorField::create(
89
							'FeatureOneContent',
90
							_t('BaseHomePage.FeatureContentFieldLabel','Content')
91
						),
92
						TextField::create(
93
							'FeatureOneButtonText',
94
							_t('BaseHomePage.FeatureButtonText','Button text')
95
						),
96
						TreeDropdownField::create(
97
							'FeatureOneLinkID',
98
							_t('BaseHomePage.FeatureLink','Page to link to'),
99
							'SiteTree'
100
						)->setDescription(_t('BaseHomePage.ButtonTextRequired','Button text must be filled in'))
101
					)
102
				)->setHeadingLevel(3)
103
			);
104
			$dropdownField->setEmptyString('none');
105
106
			$fields->addFieldToTab('Root.Features', ToggleCompositeField::create('FeatureTwo', _t('SiteTree.FeatureTwo', 'Feature Two'),
107
				array(
108
					TextField::create('FeatureTwoTitle', _t('BaseHomePage.Title','Title')),
109
					$dropdownField = DropdownField::create(
110
						'FeatureTwoCategory',
111
						_t('BaseHomePage.FeatureCategoryDropdown','Category icon'),
112
						singleton('BaseHomePage')->dbObject('FeatureTwoCategory')->enumValues()
113
					),
114
					HTMLEditorField::create(
115
						'FeatureTwoContent',
116
						_t('BaseHomePage.FeatureContentFieldLabel','Content')
117
					),
118
					TextField::create(
119
						'FeatureTwoButtonText',
120
						_t('BaseHomePage.FeatureButtonText','Button text')
121
					),
122
					TreeDropdownField::create(
123
						'FeatureTwoLinkID',
124
						_t('BaseHomePage.FeatureLink','Page to link to'),
125
						'SiteTree'
126
					)->setDescription(_t('BaseHomePage.ButtonTextRequired','Button text must be filled in'))
127
				)
128
				)->setHeadingLevel(3)
129
			);
130
			$dropdownField->setEmptyString('none');
131
		});
132
133
		return parent::getCMSFields();
134
	}
135
}
136
137
class BaseHomePage_Controller extends Page_Controller {
0 ignored issues
show
Bug introduced by
The type Page_Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
138
139
	public function getNewsPage() {
140
		return NewsHolder::get_one('NewsHolder');
141
	}
142
143
	/**
144
	 * @param int $amount The amount of items to provide.
145
	 */
146
	public function getNewsItems($amount = 2) {
147
		$newsHolder = $this->getNewsPage();
148
		if ($newsHolder) {
149
			$controller = new NewsHolder_Controller($newsHolder);
150
			return $controller->Updates()->limit($amount);
151
		}
152
	}
153
}
154