Passed
Push — master ( c3cb05...1bd367 )
by Julito
09:55
created

Toolbar::getPlugins()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Component\Editor;
5
6
use Symfony\Component\Routing\RouterInterface;
7
8
/**
9
 * Class Toolbar.
10
 *
11
 * @package Chamilo\CoreBundle\Component\Editor
12
 */
13
class Toolbar
14
{
15
    public $config = [];
16
    public $urlGenerator;
17
    public $plugins = [];
18
    public $defaultPlugins = [];
19
20
    /**
21
     * Toolbar constructor.
22
     *
23
     * @param RouterInterface $urlGenerator
24
     * @param null            $toolbar
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $toolbar is correct as it would always require null to be passed?
Loading history...
25
     * @param array           $config
26
     * @param null            $prefix
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $prefix is correct as it would always require null to be passed?
Loading history...
27
     */
28
    public function __construct(
29
        $urlGenerator,
30
        $toolbar = null,
31
        $config = [],
32
        $prefix = null
33
    ) {
34
        $this->urlGenerator = $urlGenerator;
35
36
        if (!empty($toolbar)) {
37
            $class = __NAMESPACE__."\\".$prefix."\\Toolbar\\".$toolbar;
38
            if (class_exists($class)) {
39
                $this->setConfig($config);
40
                $toolbarObj = new $class($urlGenerator, $toolbar, $config);
41
                $config = $toolbarObj->getConfig();
42
43
                if (api_get_configuration_value('full_ckeditor_toolbar_set')) {
44
                    $basicClass = __NAMESPACE__."\\".$prefix."\\Toolbar\\Basic";
45
                    $basicObj = new $basicClass($urlGenerator, $toolbar, $config);
46
                    $basicConfig = $basicObj->getConfig();
47
48
                    if (api_get_setting('more_buttons_maximized_mode') === 'true') {
49
                        if (isset($config['toolbar'])) {
50
                            unset($config['toolbar']);
51
                        }
52
53
                        $config['toolbar_minToolbar'] = $basicConfig['toolbar_minToolbar'];
54
                        $config['toolbar_maxToolbar'] = $basicConfig['toolbar_maxToolbar'];
55
                    }
56
57
                    $config['height'] = '85px';
58
                    $config['toolbarCanCollapse'] = true;
59
                    $config['toolbarStartupExpanded'] = false;
60
                }
61
62
                $this->updateConfig($config);
63
            }
64
        }
65
66
        if (!empty($config)) {
67
            $this->updateConfig($config);
68
        }
69
    }
70
71
    /**
72
     * @return RouterInterface
73
     */
74
    public function getUrlGenerator()
75
    {
76
        return $this->urlGenerator;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getPluginsToString()
83
    {
84
        $plugins = array_filter(
85
            array_merge(
86
                $this->getDefaultPlugins(),
87
                $this->getPlugins(),
88
                $this->getConditionalPlugins()
89
            )
90
        );
91
92
        return
93
            $this->getConfigAttribute('extraPlugins').
0 ignored issues
show
Bug introduced by
Are you sure $this->getConfigAttribute('extraPlugins') of type array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
            /** @scrutinizer ignore-type */ $this->getConfigAttribute('extraPlugins').
Loading history...
94
            implode(',', $plugins);
95
    }
96
97
    /**
98
     * Get plugins by default in all editors in the platform.
99
     *
100
     * @return array
101
     */
102
    public function getDefaultPlugins()
103
    {
104
        return $this->defaultPlugins;
105
    }
106
107
    /**
108
     * Get fixed plugins depending of the toolbar.
109
     *
110
     * @return array
111
     */
112
    public function getPlugins()
113
    {
114
        return $this->plugins;
115
    }
116
117
    /**
118
     * Get dynamic/conditional plugins depending of platform/course settings.
119
     *
120
     * @return array
121
     */
122
    public function getConditionalPlugins()
123
    {
124
        return [];
125
    }
126
127
    /**
128
     * @param array $config
129
     */
130
    public function setConfig(array $config)
131
    {
132
        $this->config = $config;
133
    }
134
135
    /**
136
     * @param array $config
137
     */
138
    public function updateConfig(array $config)
139
    {
140
        if (empty($this->config)) {
141
            $this->setConfig($config);
142
        } else {
143
            $this->config = array_merge($this->config, $config);
144
        }
145
    }
146
147
    /**
148
     * @return array
149
     */
150
    public function getConfig()
151
    {
152
        return $this->config;
153
    }
154
155
    /**
156
     * @param string $variable
157
     *
158
     * @return array
159
     */
160
    public function getConfigAttribute($variable)
161
    {
162
        if (isset($this->config[$variable])) {
163
            return $this->config[$variable];
164
        }
165
166
        return null;
167
    }
168
169
    /**
170
     * @param string $language
171
     */
172
    public function setLanguage($language)
173
    {
174
        $this->config['language'] = $language;
175
    }
176
}
177