|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
*@author nicolaas [at] sunnysideup.co.nz |
|
5
|
|
|
* |
|
6
|
|
|
* |
|
7
|
|
|
**/ |
|
8
|
|
|
|
|
9
|
|
|
class CallToActionPageExtension extends DataExtension |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
private static $has_one = [ |
|
|
|
|
|
|
12
|
|
|
'CallToAction' => 'CallToAction' |
|
13
|
|
|
]; |
|
14
|
|
|
|
|
15
|
|
|
private static $field_labels = [ |
|
|
|
|
|
|
16
|
|
|
'CallToAction' => 'Call to action' |
|
17
|
|
|
]; |
|
18
|
|
|
|
|
19
|
|
|
private static $field_labels_right = [ |
|
|
|
|
|
|
20
|
|
|
'CallToAction' => 'Big image with optional text' |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
public function updateCMSFields(FieldList $fields) |
|
24
|
|
|
{ |
|
25
|
|
|
$fieldLabels = $this->owner->FieldLabels(); |
|
|
|
|
|
|
26
|
|
|
$callToAction = CallToAction::singleton(); |
|
27
|
|
|
$fieldLabelsRight = Config::inst()->get('CallToActionPageExtension', 'field_labels_right'); |
|
|
|
|
|
|
28
|
|
|
$tabTitle0 = $callToAction->i18n_singular_name(); |
|
29
|
|
|
$link1 = '/admin/calltoaction/'; |
|
30
|
|
|
$tabTitle1 = _t('CallToActionPageExtension.CREATE_NEW', 'view all'); |
|
31
|
|
|
if ($this->owner->CallToActionID) { |
|
32
|
|
|
$callToAction = $this->owner->CallToAction(); |
|
33
|
|
|
if ($callToAction && $callToAction->exists()) { |
|
34
|
|
|
$link2 = $this->owner->CallToAction()->CMSEditLink(); |
|
35
|
|
|
$tabTitle2 = _t('CallToActionPageExtension.EDIT_CURRENT', 'edit').' '.$callToAction->getTitle(); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
if (! isset($link2)) { |
|
39
|
|
|
$link2 = $callToAction->CMSAddLink(); |
|
40
|
|
|
$tabTitle2 = _t('CallToActionPageExtension.CREATE_NEW', 'create new').' '.$callToAction->i18n_singular_name(); |
|
41
|
|
|
} |
|
42
|
|
|
$fields->addFieldsToTab( |
|
43
|
|
|
'Root.'.$tabTitle0, |
|
44
|
|
|
[ |
|
45
|
|
|
DropdownField::create( |
|
46
|
|
|
'CallToActionID', |
|
47
|
|
|
_t('CallToActionPageExtension.SELECT', 'select'), |
|
48
|
|
|
[0 => _t('CallToActionPageExtension.PLEASE_SELECT', '-- please select --')] +CallToAction::get()->map()->toArray() |
|
49
|
|
|
), |
|
50
|
|
|
LiteralField::create( |
|
51
|
|
|
'CallToActionList', |
|
52
|
|
|
'<h2> |
|
53
|
|
|
✎ |
|
54
|
|
|
<a href="'.$link1.'" target="_blank">'.$tabTitle1.'</a> | |
|
55
|
|
|
<a href="'.$link2.'" target="_blank">'.$tabTitle2.'</a> |
|
|
|
|
|
|
56
|
|
|
<h2>' |
|
57
|
|
|
), |
|
58
|
|
|
LiteralField::create( |
|
59
|
|
|
'CallToActionEdit', |
|
60
|
|
|
'' |
|
61
|
|
|
) |
|
62
|
|
|
] |
|
63
|
|
|
); |
|
64
|
|
|
return $fields; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.