|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CWP\CWP\PageTypes; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Model\RedirectorPage; |
|
6
|
|
|
use SilverStripe\Forms\FieldList; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* FooterHolder is intended as an invisible container for footer links and pages. |
|
10
|
|
|
* All child pages will be shown within the footer area of the site. |
|
11
|
|
|
* Use **RedirectorPage** if you just need a link. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
class FooterHolder extends RedirectorPage |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
private static $description = 'Holder page that displays all child pages as links in the footer'; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
private static $singular_name = 'Footer Holder'; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
private static $plural_name = 'Footer Holders'; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
private static $defaults = [ |
|
|
|
|
|
|
24
|
|
|
'ShowInMenus' => 0, |
|
25
|
|
|
'ShowInSearch' => 0, |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
private static $table_name = 'FooterHolder'; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
public function getCMSFields() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
33
|
|
|
$fields->removeByName('RedirectorDescHeader'); |
|
34
|
|
|
$fields->removeByName('RedirectionType'); |
|
35
|
|
|
$fields->removeByName('LinkToID'); |
|
36
|
|
|
$fields->removeByName('ExternalURL'); |
|
37
|
|
|
}); |
|
38
|
|
|
return parent::getCMSFields(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Return the link to the first child page. |
|
43
|
|
|
*/ |
|
44
|
|
|
public function redirectionLink() |
|
45
|
|
|
{ |
|
46
|
|
|
$childPage = $this->Children()->first(); |
|
47
|
|
|
|
|
48
|
|
|
if ($childPage) { |
|
49
|
|
|
// If we're linking to another redirectorpage then just return the URLSegment, to prevent a cycle of |
|
50
|
|
|
// redirector pages from causing an infinite loop. Instead, they will cause a 30x redirection loop in |
|
51
|
|
|
// the browser, but this can be handled sufficiently gracefully by the browser. |
|
52
|
|
|
if ($childPage instanceof RedirectorPage) { |
|
53
|
|
|
return $childPage->regularLink(); |
|
54
|
|
|
} |
|
55
|
|
|
// For all other pages, just return the link of the page. |
|
56
|
|
|
return $childPage->Link(); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function syncLinkTracking() |
|
61
|
|
|
{ |
|
62
|
|
|
// If we don't have anything to link to, then we have a broken link. |
|
63
|
|
|
if (!$this->Children()) { |
|
64
|
|
|
$this->HasBrokenLink = true; |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|