Completed
Push — master ( b59a65...98f778 )
by Eric
9s
created

Configuration::createFilebrowsersNode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Ivory CKEditor package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\CKEditorBundle\DependencyInjection;
13
14
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15
use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17
/**
18
 * Ivory CKEditor configuration.
19
 *
20
 * @author GeLo <[email protected]>
21
 */
22
class Configuration implements ConfigurationInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getConfigTreeBuilder()
28
    {
29
        $treeBuilder = $this->createTreeBuilder();
30
        $treeBuilder
31
            ->root('ivory_ck_editor')
32
            ->children()
33
                ->booleanNode('enable')->end()
34
                ->booleanNode('async')->end()
35
                ->booleanNode('auto_inline')->end()
36
                ->booleanNode('inline')->end()
37
                ->booleanNode('autoload')->end()
38
                ->booleanNode('jquery')->end()
39
                ->booleanNode('require_js')->end()
40
                ->booleanNode('input_sync')->end()
41
                ->scalarNode('base_path')->end()
42
                ->scalarNode('js_path')->end()
43
                ->scalarNode('jquery_path')->end()
44
                ->scalarNode('default_config')->end()
45
                ->append($this->createConfigsNode())
46
                ->append($this->createPluginsNode())
47
                ->append($this->createStylesNode())
48
                ->append($this->createTemplatesNode())
49
                ->append($this->createFilebrowsersNode())
50
                ->append($this->createToolbarsNode())
51
            ->end();
52
53
        return $treeBuilder;
54
    }
55
56
    /**
57
     * Creates the configs node.
58
     *
59
     * @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The configs node.
60
     */
61
    private function createConfigsNode()
62
    {
63
        return $this->createNode('configs')
64
            ->normalizeKeys(false)
65
            ->useAttributeAsKey('name')
66
            ->prototype('array')
67
                ->normalizeKeys(false)
68
                ->useAttributeAsKey('name')
69
                ->prototype('variable')->end()
70
            ->end();
71
    }
72
73
    /**
74
     * Creates the plugins node.
75
     *
76
     * @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The plugins node.
77
     */
78
    private function createPluginsNode()
79
    {
80
        return $this->createNode('plugins')
81
            ->normalizeKeys(false)
82
            ->useAttributeAsKey('name')
83
            ->prototype('array')
84
                ->children()
85
                    ->scalarNode('path')->end()
86
                    ->scalarNode('filename')->end()
87
                ->end()
88
            ->end();
89
    }
90
91
    /**
92
     * Creates the styles node.
93
     *
94
     * @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The styles node.
95
     */
96
    private function createStylesNode()
97
    {
98
        return $this->createNode('styles')
99
            ->normalizeKeys(false)
100
            ->useAttributeAsKey('name')
101
            ->prototype('array')
102
                ->prototype('array')
103
                    ->children()
104
                        ->scalarNode('name')->end()
105
                        ->scalarNode('type')->end()
106
                        ->scalarNode('widget')->end()
107
                        ->variableNode('element')->end()
108
                        ->arrayNode('styles')
109
                            ->normalizeKeys(false)
110
                            ->useAttributeAsKey('name')
111
                            ->prototype('scalar')->end()
112
                        ->end()
113
                        ->arrayNode('attributes')
114
                            ->normalizeKeys(false)
115
                            ->useAttributeAsKey('name')
116
                            ->prototype('scalar')->end()
117
                        ->end()
118
                    ->end()
119
                ->end()
120
            ->end();
121
    }
122
123
    /**
124
     * Creates the templates node.
125
     *
126
     * @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The templates node.
127
     */
128
    private function createTemplatesNode()
129
    {
130
        return $this->createNode('templates')
131
            ->normalizeKeys(false)
132
            ->useAttributeAsKey('name')
133
            ->prototype('array')
134
                ->children()
135
                    ->scalarNode('imagesPath')->end()
136
                    ->arrayNode('templates')
137
                        ->prototype('array')
138
                            ->children()
139
                                ->scalarNode('title')->end()
140
                                ->scalarNode('image')->end()
141
                                ->scalarNode('description')->end()
142
                                ->scalarNode('html')->end()
143
                            ->end()
144
                        ->end()
145
                    ->end()
146
                ->end()
147
            ->end();
148
    }
149
150
    /**
151
     * Creates the filebrowsers node.
152
     *
153
     * @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The filebrowsers node.
154
     */
155
    private function createFilebrowsersNode()
156
    {
157
        return $this->createNode('filebrowsers')
158
            ->useAttributeAsKey('name')
159
            ->prototype('scalar')
160
            ->end();
161
    }
162
163
    /**
164
     * Creates the toolbars node.
165
     *
166
     * @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The toolbars node.
167
     */
168
    private function createToolbarsNode()
169
    {
170
        return $this->createNode('toolbars')
171
            ->addDefaultsIfNotSet()
172
            ->children()
173
                ->arrayNode('configs')
174
                    ->useAttributeAsKey('name')
175
                    ->prototype('array')
176
                        ->prototype('variable')->end()
177
                    ->end()
178
                ->end()
179
                ->arrayNode('items')
180
                    ->useAttributeAsKey('name')
181
                    ->prototype('array')
182
                        ->prototype('variable')->end()
183
                    ->end()
184
                ->end()
185
            ->end();
186
    }
187
188
    /**
189
     * Creates a node.
190
     *
191
     * @param string $name The node name.
192
     *
193
     * @return \Symfony\Component\Config\Definition\Builder\NodeDefinition The node.
194
     */
195
    private function createNode($name)
196
    {
197
        return $this->createTreeBuilder()->root($name);
198
    }
199
200
    /**
201
     * Creates a tree builder.
202
     *
203
     * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder.
204
     */
205
    private function createTreeBuilder()
206
    {
207
        return new TreeBuilder();
208
    }
209
}
210