Passed
Pull Request — master (#13)
by Robbie
02:45
created

CwpSiteTreeExtension   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateFieldLabels() 0 3 1
A updateSettingsFields() 0 12 1
1
<?php
2
3
namespace CWP\CWP\Extensions;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\LiteralField;
7
use SilverStripe\Forms\CheckboxField;
8
use SilverStripe\ORM\DataExtension;
9
10
class CwpSiteTreeExtension extends DataExtension
11
{
12
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
13
        'ShowPageUtilities' => 'Boolean(1)'
14
    );
15
16
    private static $defaults = array(
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
17
        'ShowPageUtilities' => true
18
    );
19
20
    /**
21
     * Modify the settings for a SiteTree
22
     *
23
     * {@inheritDoc}
24
     *
25
     * @param FieldList $fields
26
     */
27
    public function updateSettingsFields(FieldList $fields)
28
    {
29
        $helpText = _t(
30
            'SiteTree.SHOW_PAGE_UTILITIES_HELP',
31
            'You can disable page utilities (print, share, etc) for this page'
32
        );
33
34
        $fields->addFieldsToTab(
35
            'Root.Settings',
36
            array(
37
                LiteralField::create('PageUtilitiesHelp', $helpText),
0 ignored issues
show
Bug introduced by
'PageUtilitiesHelp' 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

37
                LiteralField::create(/** @scrutinizer ignore-type */ 'PageUtilitiesHelp', $helpText),
Loading history...
38
                CheckboxField::create('ShowPageUtilities', $this->owner->fieldLabel('ShowPageUtilities'))
39
            )
40
        );
41
    }
42
43
    public function updateFieldLabels(&$labels)
44
    {
45
        $labels['ShowPageUtilities'] = _t('SiteTree.SHOW_PAGE_UTILITIES', 'Show page utilities?');
46
    }
47
}
48