|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\SunnysideupThemeBackend\Extensions; |
|
4
|
|
|
|
|
5
|
|
|
use Page; |
|
6
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
7
|
|
|
use SilverStripe\Forms\EmailField; |
|
8
|
|
|
use SilverStripe\Forms\FieldList; |
|
9
|
|
|
use SilverStripe\Forms\TextField; |
|
10
|
|
|
use SilverStripe\Forms\TreeDropdownField; |
|
11
|
|
|
use SilverStripe\ORM\DataExtension; |
|
12
|
|
|
use SilverStripe\ORM\DB; |
|
13
|
|
|
use SilverStripe\SiteConfig\SiteConfig; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
*@author nicolaas [at] sunnysideup.co.nz |
|
17
|
|
|
* |
|
18
|
|
|
* |
|
19
|
|
|
**/ |
|
20
|
|
|
|
|
21
|
|
|
class SiteConfigExtras extends DataExtension |
|
22
|
|
|
{ |
|
23
|
|
|
private static $db = [ |
|
24
|
|
|
'CopyrightNotice' => 'Varchar', |
|
25
|
|
|
'PhoneNumber' => 'PhoneField', |
|
26
|
|
|
'Email' => 'EmailAddress', |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
private static $has_one = [ |
|
30
|
|
|
'ClimatePositivePage' => Page::class, |
|
31
|
|
|
'ShopifyPartnerPage' => Page::class, |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
public function updateCMSFields(FieldList $fields) |
|
35
|
|
|
{ |
|
36
|
|
|
$fields->addFieldsToTab( |
|
37
|
|
|
'Root.PageElements', |
|
38
|
|
|
[ |
|
39
|
|
|
TextField::create('CopyrightNotice', 'Copyright notice'), |
|
40
|
|
|
TextField::create('PhoneNumber', 'Phone Number'), |
|
41
|
|
|
EmailField::create('Email', 'Email'), |
|
42
|
|
|
TreeDropdownField::create('ClimatePositivePageID', 'Climate Positive Page', SiteTree::class), |
|
43
|
|
|
TreeDropdownField::create('ShopifyPartnerPageID', 'Shopify Partner Page', SiteTree::class), |
|
44
|
|
|
] |
|
45
|
|
|
); |
|
46
|
|
|
return $fields; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function onBeforeWrite() |
|
50
|
|
|
{ |
|
51
|
|
|
parent::onBeforeWrite(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function requireDefaultRecords() |
|
55
|
|
|
{ |
|
56
|
|
|
$update = []; |
|
57
|
|
|
$siteConfig = SiteConfig::current_site_config(); |
|
58
|
|
|
|
|
59
|
|
|
if (! $siteConfig->CopyrightNotice) { |
|
60
|
|
|
$siteConfig->CopyrightNotice = date('Y') . ' ' . $siteConfig->Title; |
|
61
|
|
|
$update[] = 'created default entry for CopyrightNotice'; |
|
62
|
|
|
} |
|
63
|
|
|
if (count($update)) { |
|
64
|
|
|
$siteConfig->write(); |
|
65
|
|
|
DB::alteration_message($siteConfig->ClassName . ' created/updated: ' . implode(' --- ', $update), 'created'); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|