Completed
Push — master ( 1c115b...b55b98 )
by Nicola
06:56
created

Configuration::silverstrap_settings()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 0
1
<?php
2
3
namespace eNTiDi\Silverstrap;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\Core\Config\Config;
7
use SilverStripe\View\ArrayData;
8
use SilverStripe\View\TemplateGlobalProvider;
9
10
/**
11
 * Provide access to the layout used by the Silverstrap theme.
12
 *
13
 * @package silverstrap
14
 * @subpackage code
15
 */
16
class Configuration implements TemplateGlobalProvider
17
{
18
    /**
19
     * Array of Silverstrap layouts available.
20
     */
21
    private static $layouts;
0 ignored issues
show
Unused Code introduced by
The property $layouts is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
22
23
24
    /**
25
     * Return the proper layout, depending on the controller.
26
     *
27
     * Check `docs/en/usage.md` to know the exact algorithm used to
28
     * look up the proper layout.
29
     */
30
    public static function silverstrap_settings()
31
    {
32
        $controller = Director::get_current_page();
33
        $layouts    = Config::inst()->get(self::class, 'layouts');
34
        if (array_key_exists($controller->SilverstrapLayout, $layouts)) {
35
            $layout = $controller->SilverstrapLayout;
36
        } elseif (array_key_exists($controller->class, $layouts)) {
37
            $layout = $controller->class;
38
        } else {
39
            $layout = 'default';
40
        }
41
        return ArrayData::create($layouts[$layout]);
42
    }
43
44
    public static function get_template_global_variables()
45
    {
46
        return [
47
            'Silverstrap' => 'silverstrap_settings',
48
        ];
49
    }
50
}
51