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