Passed
Push — 1.8 ( 8b2854...6b63e4 )
by Robbie
15:17 queued 11:24
created

FooterHolder::syncLinkTracking()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
1
<?php
2
/**
3
 * FooterHolder is intended as an invisible container for footer links and pages.
4
 * All child pages will be shown within the footer area of the site.
5
 * Use **RedirectorPage** if you just need a link.
6
 */
7
8
class FooterHolder extends RedirectorPage {
9
10
	private static $description = 'Holder page that displays all child pages as links in the footer';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
11
12
	private static $singular_name = 'Footer Holder';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
13
14
	private static $plural_name = 'Footer Holders';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
15
16
	private static $defaults = array(
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
17
		'ShowInMenus' => 0,
18
		'ShowInSearch' => 0
19
	);
20
21
	public function getCMSFields() {
22
		$this->beforeUpdateCMSFields(function (FieldList $fields) {
23
			$fields->removeByName('RedirectorDescHeader');
24
			$fields->removeByName('RedirectionType');
25
			$fields->removeByName('LinkToID');
26
			$fields->removeByName('ExternalURL');
27
		});
28
		return parent::getCMSFields();
29
	}
30
31
	/**
32
	 * Return the link to the first child page.
33
	 */
34
	public function redirectionLink() {
35
		$childPage = $this->Children()->first();
36
37
		if($childPage) {
38
			// If we're linking to another redirectorpage then just return the URLSegment, to prevent a cycle of redirector
39
			// pages from causing an infinite loop.  Instead, they will cause a 30x redirection loop in the browser, but
40
			// this can be handled sufficiently gracefully by the browser.
41
			if ($childPage instanceof RedirectorPage) {
42
				return $childPage->regularLink();
43
44
			// For all other pages, just return the link of the page.
45
			} else {
46
				return $childPage->Link();
47
			}
48
		}
49
	}
50
51
	public function syncLinkTracking() {
52
		// If we don't have anything to link to, then we have a broken link.
53
		if (!$this->Children()) {
54
			$this->HasBrokenLink = true;
0 ignored issues
show
Bug Best Practice introduced by
The property HasBrokenLink does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
55
		}
56
	}
57
}
58
59
class FooterHolder_Controller extends RedirectorPage_Controller {
60
61
}
62