Completed
Push — master ( b28dd3...cc924e )
by Robbie
03:15
created

ChecIOExtension::contentcontrollerInit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
class ChecIOExtension extends SiteTreeExtension
4
{
5
    /**
6
     * Loads the third party javascript during Controller->init()
7
     */
8
    public function contentcontrollerInit()
9
    {
10
        if ($jsPath = ChecIOShortcode::config()->get('third-party-js')) {
11
            Requirements::javascript($jsPath);
12
        }
13
    }
14
15
    /**
16
     * Tries to fetch the inline chec.io JS from cache, failing which it gets it from the URL.
17
     * Should your theme clear requirements, placing this before the closing body tag ensures
18
     * that it always gets loaded.
19
     * @return string
20
     */
21
    public function getChecIOJs()
22
    {
23
        if ($jsPath = ChecIOShortcode::config()->get('third-party-js')) {
24
            return sprintf('<script type="text/javascript" src="%s"></script>', $jsPath);
25
        }
26
        return '';
27
    }
28
}
29