Completed
Pull Request — master (#13)
by Robbie
02:33
created

CustomSiteConfig   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B updateCMSFields() 0 43 1
1
<?php
2
3
namespace CWP\CWP\Extensions;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\TextField;
7
use SilverStripe\ORM\DataExtension;
8
9
/**
10
 * Adds new global settings.
11
 */
12
class CustomSiteConfig extends DataExtension
13
{
14
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
15
        'GACode' => 'Varchar(16)',
16
        'FacebookURL' => 'Varchar(256)', // multitude of ways to link to Facebook accounts, best to leave it open.
17
        'TwitterUsername' => 'Varchar(16)', // max length of Twitter username 15
18
    );
19
20
    public function updateCMSFields(FieldList $fields)
21
    {
22
        $fields->addFieldToTab(
23
            'Root.Main',
24
            $gaCode = TextField::create(
25
                'GACode',
0 ignored issues
show
Bug introduced by
'GACode' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
                /** @scrutinizer ignore-type */ 'GACode',
Loading history...
26
                _t('CwpConfig.GaField', 'Google Analytics account')
27
            )
28
        );
29
30
        $gaCode->setRightTitle(
31
            _t(
32
                'CwpConfig.GaFieldDesc',
33
                'Account number to be used all across the site (in the format <strong>UA-XXXXX-X</strong>)'
34
            )
35
        );
36
37
        $fields->findOrMakeTab('Root.SocialMedia', _t('CustomSiteConfig.SocialMediaTab', 'Social Media'));
38
39
        $fields->addFieldToTab(
40
            'Root.SocialMedia',
41
            $facebookURL = TextField::create(
42
                'FacebookURL',
43
                _t('CwpConfig.FbField', 'Facebook UID or username')
44
            )
45
        );
46
        $facebookURL->setRightTitle(
47
            _t(
48
                'CwpConfig.FbFieldDesc',
49
                'Facebook link (everything after the "http://facebook.com/", eg http://facebook.com/'
50
                . '<strong>username</strong> or http://facebook.com/<strong>pages/108510539573</strong>)'
51
            )
52
        );
53
54
        $fields->addFieldToTab(
55
            'Root.SocialMedia',
56
            $twitterUsername = TextField::create(
57
                'TwitterUsername',
58
                _t('CwpConfig.TwitterField', 'Twitter username')
59
            )
60
        );
61
        $twitterUsername->setRightTitle(
62
            _t('CwpConfig.TwitterFieldDesc', 'Twitter username (eg, http://twitter.com/<strong>username</strong>)')
63
        );
64
    }
65
}
66