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\Twig; |
13
|
|
|
|
14
|
|
|
use Ivory\CKEditorBundle\Renderer\CKEditorRendererInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author GeLo <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class CKEditorExtension extends \Twig_Extension implements CKEditorRendererInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var CKEditorRendererInterface |
23
|
|
|
*/ |
24
|
|
|
private $renderer; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param CKEditorRendererInterface $renderer |
28
|
|
|
*/ |
29
|
70 |
|
public function __construct(CKEditorRendererInterface $renderer) |
30
|
|
|
{ |
31
|
70 |
|
$this->renderer = $renderer; |
32
|
70 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
10 |
|
public function getFunctions() |
38
|
|
|
{ |
39
|
10 |
|
$options = ['is_safe' => ['html']]; |
40
|
|
|
|
41
|
|
|
return [ |
42
|
10 |
|
new \Twig_SimpleFunction('ckeditor_base_path', [$this, 'renderBasePath'], $options), |
43
|
10 |
|
new \Twig_SimpleFunction('ckeditor_js_path', [$this, 'renderJsPath'], $options), |
44
|
10 |
|
new \Twig_SimpleFunction('ckeditor_widget', [$this, 'renderWidget'], $options), |
45
|
10 |
|
new \Twig_SimpleFunction('ckeditor_destroy', [$this, 'renderDestroy'], $options), |
46
|
10 |
|
new \Twig_SimpleFunction('ckeditor_plugin', [$this, 'renderPlugin'], $options), |
47
|
10 |
|
new \Twig_SimpleFunction('ckeditor_styles_set', [$this, 'renderStylesSet'], $options), |
48
|
10 |
|
new \Twig_SimpleFunction('ckeditor_template', [$this, 'renderTemplate'], $options), |
49
|
8 |
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
40 |
|
public function renderBasePath($basePath) |
56
|
|
|
{ |
57
|
40 |
|
return $this->renderer->renderBasePath($basePath); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
40 |
|
public function renderJsPath($jsPath) |
64
|
|
|
{ |
65
|
40 |
|
return $this->renderer->renderJsPath($jsPath); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
50 |
|
public function renderWidget($id, array $config, array $options = []) |
72
|
|
|
{ |
73
|
50 |
|
return $this->renderer->renderWidget($id, $config, $options); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
50 |
|
public function renderDestroy($id) |
80
|
|
|
{ |
81
|
50 |
|
return $this->renderer->renderDestroy($id); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
10 |
|
public function renderPlugin($name, array $plugin) |
88
|
|
|
{ |
89
|
10 |
|
return $this->renderer->renderPlugin($name, $plugin); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
10 |
|
public function renderStylesSet($name, array $stylesSet) |
96
|
|
|
{ |
97
|
10 |
|
return $this->renderer->renderStylesSet($name, $stylesSet); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
10 |
|
public function renderTemplate($name, array $template) |
104
|
|
|
{ |
105
|
10 |
|
return $this->renderer->renderTemplate($name, $template); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
70 |
|
public function getName() |
112
|
|
|
{ |
113
|
70 |
|
return 'ivory_ckeditor'; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|