Passed
Push — master ( 8ab115...ba85c8 )
by Nicolaas
10:27
created

PageExtension::updateSettingsFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 1
dl 0
loc 16
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace Sunnysideup\SimpleTemplateCaching\Extensions;
4
5
use SilverStripe\Forms\CheckboxField;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\NumericField;
8
use SilverStripe\ORM\DataExtension;
9
use SilverStripe\SiteConfig\SiteConfig;
10
11
/**
12
 * Class \Sunnysideup\SimpleTemplateCaching\Extensions\PageExtension.
13
 *
14
 * @property Page|PageExtension $owner
15
 * @property bool $NeverCachePublicly
16
 * @property bool $PublicCacheDurationInSeconds
17
 */
18
class PageExtension extends DataExtension
19
{
20
    private static $db = [
21
        'NeverCachePublicly' => 'Boolean',
22
        'PublicCacheDurationInSeconds' => 'Boolean',
23
    ];
24
25
    public function updateSettingsFields(FieldList $fields)
26
    {
27
        $fields->addFieldsToTab(
28
            'Root.Cache',
29
            [
30
                CheckboxField::create('NeverCachePublicly', 'Never cache this page publicly (so that all users see the same page)'),
31
                NumericField::create(
32
                    'PublicCacheDurationInSeconds',
33
                    'Number of caching seconds for public users (0 = no caching)'
34
                )
35
                    ->setDescription(
36
                        '
37
                        Use with care!
38
                        This should only be used on pages that should be the same for all users and that should be accessible publicly.
39
                        You can also set this value <a href="/admin/settings#Root_Caching">for the whole site</a> .
40
                        The current value is ' . SiteConfig::current_site_config()->PublicCacheDurationInSeconds . ' seconds.'
41
                    ),
42
43
            ]
44
        );
45
    }
46
}
47