PageControllerExtension::IsGetSiteControlPage()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Sunnysideup\GetSiteControl\Extensions;
4
5
use SilverStripe\SiteConfig\SiteConfig;
6
use SilverStripe\View\Requirements;
7
use SilverStripe\Core\Extension;
8
9
10
//todo: add Extension use statement
11
12
class PageControllerExtension extends Extension
13
{
14
    public function onAfterInit()
15
    {
16
        if (
17
            ! empty(SiteConfig::current_site_config()->GetSiteControlAPI) &&
18
            $this->IsGetSiteControlPage()
19
        ) {
20
            Requirements::javascript(
21
                '//l.getsitecontrol.com/' . SiteConfig::current_site_config()->GetSiteControlAPI . '.js',
22
                [
23
                    'async' => true,
24
                ]
25
            );
26
        }
27
    }
28
29
    public function IsGetSiteControlPage(): bool
30
    {
31
        if ($this->getOwner()->hasMethod('IsGetSiteControlEnabledOnPageLevelOverride')) {
32
            return $this->getOwner()->IsGetSiteControlEnabledOnPageLevelOverride();
33
        }
34
35
        return
36
            $this->getOwner()->IsGetSiteControlEnabledOnPageLevel() &&
37
            $this->getOwner()->dataRecord->ActiveGetSiteControl
38
        ;
39
    }
40
}
41