1
|
|
|
<?php |
2
|
|
|
class Quicklink extends DataObject { |
3
|
|
|
|
4
|
|
|
private static $db = array( |
|
|
|
|
5
|
|
|
'Name' => 'Varchar(255)', |
6
|
|
|
'ExternalLink' => 'Varchar(255)', |
7
|
|
|
'SortOrder' => 'Int' |
8
|
|
|
); |
9
|
|
|
|
10
|
|
|
private static $has_one = array( |
|
|
|
|
11
|
|
|
'Parent' => 'BaseHomePage', |
12
|
|
|
'InternalLink' => 'SiteTree' |
13
|
|
|
); |
14
|
|
|
|
15
|
|
|
private static $summary_fields = array( |
|
|
|
|
16
|
|
|
'Name' => 'Name', |
17
|
|
|
'InternalLink.Title' => 'Internal Link', |
18
|
|
|
'ExternalLink' => 'External Link' |
19
|
|
|
); |
20
|
|
|
|
21
|
|
|
public function fieldLabels($includerelations = true) { |
22
|
|
|
$labels = parent::fieldLabels($includerelations); |
23
|
|
|
$labels['Name'] = _t('Quicklink.NameLabel', 'Name'); |
24
|
|
|
$labels['ExternalLink'] = _t('Quicklink.ExternalLinkLabel', 'External Link'); |
25
|
|
|
$labels['SortOrder'] = _t('Quicklink.SortOrderLabel', 'Sort Order'); |
26
|
|
|
$labels['ParentID'] = _t('Quicklink.ParentRelationLabel', 'Parent'); |
27
|
|
|
$labels['InternalLinkID'] = _t('Quicklink.InternalLinkLabel', 'Internal Link'); |
28
|
|
|
|
29
|
|
|
return $labels; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getLink() { |
33
|
|
|
if ($this->ExternalLink) { |
|
|
|
|
34
|
|
|
$url = parse_url($this->ExternalLink); |
35
|
|
|
|
36
|
|
|
// if no scheme set in the link, default to http |
37
|
|
|
if(!isset($url['scheme'])) { |
38
|
|
|
return 'http://' . $this->ExternalLink; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $this->ExternalLink; |
42
|
|
|
} elseif ($this->InternalLinkID) { |
|
|
|
|
43
|
|
|
return $this->InternalLink()->Link(); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function canCreate($member = null) { |
48
|
|
|
return $this->Parent()->canCreate($member); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function canEdit($member = null) { |
52
|
|
|
return $this->Parent()->canEdit($member); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function canDelete($member = null) { |
56
|
|
|
return $this->Parent()->canDelete($member); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function canView($member = null) { |
60
|
|
|
return $this->Parent()->canView($member); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function getCMSFields() { |
64
|
|
|
$fields = parent::getCMSFields(); |
65
|
|
|
|
66
|
|
|
$fields->removeByName('ParentID'); |
67
|
|
|
|
68
|
|
|
$externalLinkField = $fields->fieldByName('Root.Main.ExternalLink'); |
69
|
|
|
|
70
|
|
|
$fields->removeByName('ExternalLink'); |
71
|
|
|
$fields->removeByName('InternalLinkID'); |
72
|
|
|
$fields->removeByName('SortOrder'); |
73
|
|
|
$externalLinkField->addExtraClass('noBorder'); |
74
|
|
|
|
75
|
|
|
$fields->addFieldToTab('Root.Main',CompositeField::create( |
76
|
|
|
array( |
77
|
|
|
TreeDropdownField::create( |
78
|
|
|
'InternalLinkID', |
79
|
|
|
$this->fieldLabel('InternalLinkID'), |
80
|
|
|
'SiteTree' |
81
|
|
|
), |
82
|
|
|
$externalLinkField, |
83
|
|
|
$wrap = CompositeField::create( |
|
|
|
|
84
|
|
|
$extraLabel = LiteralField::create( |
85
|
|
|
'NoteOverride', |
86
|
|
|
_t('Quicklink.Note','<div class="message good notice">Note: If you specify an External Link, the Internal Link will be ignored.</div>') |
87
|
|
|
) |
88
|
|
|
) |
89
|
|
|
) |
90
|
|
|
)); |
91
|
|
|
$fields->insertBefore( |
92
|
|
|
LiteralField::create( |
93
|
|
|
'Note', |
94
|
|
|
_t( |
95
|
|
|
'Quicklink.Note2', |
96
|
|
|
'<p>Use this to specify a link to a page either on this site (Internal Link) or another site (External Link).</p>' |
97
|
|
|
) |
98
|
|
|
), |
99
|
|
|
'Name' |
|
|
|
|
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
return $fields; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|