sonata-project / SonataFormatterBundle

Compare cd1529a ... +131 ... cc64b0c

Showing 4 of 191 files from the diff.
Other files ignored by Codecov
phpstan.neon.dist has changed.
UPGRADE-4.0.md has changed.
bower.json has changed.
docs/index.rst has changed.
composer.json has changed.

@@ -13,11 +13,6 @@
Loading
13 13
14 14
namespace Sonata\FormatterBundle\Form\Type;
15 15
16 -
use FOS\CKEditorBundle\Config\CKEditorConfigurationInterface;
17 -
use FOS\CKEditorBundle\Model\ConfigManagerInterface;
18 -
use FOS\CKEditorBundle\Model\PluginManagerInterface;
19 -
use FOS\CKEditorBundle\Model\TemplateManagerInterface;
20 -
use FOS\CKEditorBundle\Model\ToolbarManagerInterface;
21 16
use Sonata\FormatterBundle\Form\EventListener\FormatterListener;
22 17
use Sonata\FormatterBundle\Formatter\PoolInterface;
23 18
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -44,76 +39,12 @@
Loading
44 39
     */
45 40
    protected $translator;
46 41
47 -
    /**
48 -
     * @var ConfigManagerInterface
49 -
     *
50 -
     * @deprecated since sonata-project/formatter bundle 4.3 and will be removed in version 5.0.
51 -
     */
52 -
    protected $configManager;
53 -
54 -
    /**
55 -
     * @var PluginManagerInterface
56 -
     */
57 -
    protected $pluginManager;
58 -
59 -
    /**
60 -
     * @var CKEditorConfigurationInterface
61 -
     */
62 -
    private $ckEditorConfiguration;
63 -
64 -
    /**
65 -
     * @var TemplateManagerInterface
66 -
     */
67 -
    private $templateManager;
68 -
69 -
    /**
70 -
     * @var ToolbarManagerInterface
71 -
     */
72 -
    private $toolbarManager;
73 -
74 -
    /**
75 -
     * NEXT_MAJOR: Change signature for
76 -
     * (PoolInterface $pool, TranslatorInterface $translator, CKEditorConfigurationInterface $ckEditorConfiguration).
77 -
     *
78 -
     * @param ConfigManagerInterface|CKEditorConfigurationInterface $configManagerOrCkEditorConfiguration
79 -
     */
80 42
    public function __construct(
81 43
        PoolInterface $pool,
82 -
        TranslatorInterface $translator,
83 -
        object $configManagerOrCkEditorConfiguration,
84 -
        ?PluginManagerInterface $pluginManager = null,
85 -
        ?TemplateManagerInterface $templateManager = null,
86 -
        ?ToolbarManagerInterface $toolbarManager = null
44 +
        TranslatorInterface $translator
87 45
    ) {
88 -
        if (!$configManagerOrCkEditorConfiguration instanceof CKEditorConfigurationInterface) {
89 -
            @trigger_error(sprintf(
90 -
                'Passing %s as argument 3 to %s() is deprecated since sonata-project/formatter-bundle 4.3'
91 -
                .' and will throw a \TypeError in version 5.0. You must pass an instance of %s instead.',
92 -
                \get_class($configManagerOrCkEditorConfiguration),
93 -
                __METHOD__,
94 -
                CKEditorConfigurationInterface::class
95 -
            ), \E_USER_DEPRECATED);
96 -
97 -
            if (!$configManagerOrCkEditorConfiguration instanceof ConfigManagerInterface) {
98 -
                throw new \TypeError(sprintf(
99 -
                    'Argument 3 passed to %s() must be an instance of %s or %s, %s given.',
100 -
                    __METHOD__,
101 -
                    CKEditorConfigurationInterface::class,
102 -
                    ConfigManagerInterface::class,
103 -
                    \get_class($configManagerOrCkEditorConfiguration)
104 -
                ));
105 -
            }
106 -
107 -
            $this->configManager = $configManagerOrCkEditorConfiguration;
108 -
        } else {
109 -
            $this->ckEditorConfiguration = $configManagerOrCkEditorConfiguration;
110 -
        }
111 -
112 46
        $this->pool = $pool;
113 47
        $this->translator = $translator;
114 -
        $this->pluginManager = $pluginManager;
115 -
        $this->templateManager = $templateManager;
116 -
        $this->toolbarManager = $toolbarManager;
117 48
    }
118 49
119 50
    public function buildForm(FormBuilderInterface $builder, array $options): void
@@ -193,60 +124,6 @@
Loading
193 124
194 125
        $view->vars['format_field_options'] = $options['format_field_options'];
195 126
196 -
        if (null !== $this->ckEditorConfiguration) {
197 -
            $defaultConfig = $this->ckEditorConfiguration->getDefaultConfig();
198 -
            $ckeditorConfiguration = $this->ckEditorConfiguration->getConfig($defaultConfig);
199 -
        } else {//NEXT_MAJOR: Remove this case
200 -
            $defaultConfig = $this->configManager->getDefaultConfig();
201 -
202 -
            if ($this->configManager->hasConfig($defaultConfig)) {
203 -
                $ckeditorConfiguration = $this->configManager->getConfig($defaultConfig);
204 -
            } else {
205 -
                $ckeditorConfiguration = [];
206 -
            }
207 -
        }
208 -
209 -
        if (!\array_key_exists('toolbar', $ckeditorConfiguration)) {
210 -
            $ckeditorConfiguration['toolbar'] = array_values($options['ckeditor_toolbar_icons']);
211 -
        }
212 -
213 -
        if ($options['ckeditor_context']) {
214 -
            if (null !== $this->configManager) {//NEXT_MAJOR: Remove this case
215 -
                $contextConfig = $this->configManager->getConfig($options['ckeditor_context']);
216 -
            } else {
217 -
                $contextConfig = $this->ckEditorConfiguration->getConfig($options['ckeditor_context']);
218 -
            }
219 -
220 -
            $ckeditorConfiguration = array_merge($ckeditorConfiguration, $contextConfig);
221 -
        }
222 -
223 -
        if ($options['ckeditor_image_format']) {
224 -
            $ckeditorConfiguration['filebrowserImageUploadRouteParameters']['format'] = $options['ckeditor_image_format'];
225 -
        }
226 -
227 -
        if (null !== $this->ckEditorConfiguration) {
228 -
            $options['ckeditor_plugins'] = $this->ckEditorConfiguration->getPlugins();
229 -
            $options['ckeditor_templates'] = $this->ckEditorConfiguration->getTemplates();
230 -
            if (\is_string($ckeditorConfiguration['toolbar'])) {
231 -
                $ckeditorConfiguration['toolbar'] = $this->ckEditorConfiguration->getToolbar($ckeditorConfiguration['toolbar']);
232 -
            }
233 -
        } else {//NEXT_MAJOR: Remove this case
234 -
            if ($this->pluginManager->hasPlugins()) {
235 -
                $options['ckeditor_plugins'] = $this->pluginManager->getPlugins();
236 -
            }
237 -
            if ($this->templateManager->hasTemplates()) {
238 -
                $options['ckeditor_templates'] = $this->templateManager->getTemplates();
239 -
            }
240 -
            if (\is_string($ckeditorConfiguration['toolbar'])) {
241 -
                $ckeditorConfiguration['toolbar'] = $this->toolbarManager->resolveToolbar($ckeditorConfiguration['toolbar']);
242 -
            }
243 -
        }
244 -
245 -
        $view->vars['ckeditor_configuration'] = $ckeditorConfiguration;
246 -
        $view->vars['ckeditor_basepath'] = $options['ckeditor_basepath'];
247 -
        $view->vars['ckeditor_plugins'] = $options['ckeditor_plugins'];
248 -
        $view->vars['ckeditor_templates'] = $options['ckeditor_templates'];
249 -
250 127
        $view->vars['source_id'] = str_replace($view->vars['name'], $view->vars['source_field'], $view->vars['id']);
251 128
    }
252 129
@@ -269,20 +146,6 @@
Loading
269 146
            'inherit_data' => true,
270 147
            'event_dispatcher' => null,
271 148
            'format_field' => null,
272 -
            'ckeditor_toolbar_icons' => [[
273 -
                 'Bold', 'Italic', 'Underline',
274 -
                 '-', 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord',
275 -
                 '-', 'Undo', 'Redo',
276 -
                 '-', 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent',
277 -
                 '-', 'Blockquote',
278 -
                 '-', 'Image', 'Link', 'Unlink', 'Table', ],
279 -
                 ['Maximize', 'Source'],
280 -
            ],
281 -
            'ckeditor_basepath' => 'bundles/sonataformatter/vendor/ckeditor',
282 -
            'ckeditor_context' => null,
283 -
            'ckeditor_image_format' => null,
284 -
            'ckeditor_plugins' => [],
285 -
            'ckeditor_templates' => [],
286 149
            'format_field_options' => $formatFieldOptions,
287 150
            'source_field' => null,
288 151
            'source_field_options' => [

@@ -13,12 +13,6 @@
Loading
13 13
14 14
namespace Sonata\FormatterBundle\Form\Type;
15 15
16 -
use FOS\CKEditorBundle\Config\CKEditorConfigurationInterface;
17 -
use FOS\CKEditorBundle\Model\ConfigManagerInterface;
18 -
use FOS\CKEditorBundle\Model\PluginManagerInterface;
19 -
use FOS\CKEditorBundle\Model\StylesSetManagerInterface;
20 -
use FOS\CKEditorBundle\Model\TemplateManagerInterface;
21 -
use FOS\CKEditorBundle\Model\ToolbarManagerInterface;
22 16
use Symfony\Component\Form\AbstractType;
23 17
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
24 18
use Symfony\Component\Form\FormInterface;
@@ -27,167 +21,14 @@
Loading
27 21
28 22
final class SimpleFormatterType extends AbstractType
29 23
{
30 -
    /**
31 -
     * @var ConfigManagerInterface
32 -
     *
33 -
     * @deprecated since sonata-project/formatter bundle 4.3 and will be removed in version 5.0.
34 -
     */
35 -
    protected $configManager;
36 -
37 -
    /**
38 -
     * @var PluginManagerInterface
39 -
     */
40 -
    protected $pluginManager;
41 -
42 -
    /**
43 -
     * @var CKEditorConfigurationInterface
44 -
     */
45 -
    private $ckEditorConfiguration;
46 -
47 -
    /**
48 -
     * @var StylesSetManagerInterface
49 -
     */
50 -
    private $stylesSetManager;
51 -
52 -
    /**
53 -
     * @var TemplateManagerInterface
54 -
     */
55 -
    private $templateManager;
56 -
57 -
    /**
58 -
     * @var ToolbarManagerInterface
59 -
     */
60 -
    private $toolbarManager;
61 -
62 -
    /**
63 -
     * NEXT_MAJOR: Change signature for (CKEditorConfigurationInterface $ckEditorConfiguration).
64 -
     *
65 -
     * @param ConfigManagerInterface|CKEditorConfigurationInterface $configManagerOrCkEditorConfiguration
66 -
     */
67 -
    public function __construct(
68 -
        object $configManagerOrCkEditorConfiguration,
69 -
        ?PluginManagerInterface $pluginManager = null,
70 -
        ?TemplateManagerInterface $templateManager = null,
71 -
        ?StylesSetManagerInterface $stylesSetManager = null,
72 -
        ?ToolbarManagerInterface $toolbarManager = null
73 -
    ) {
74 -
        if (!$configManagerOrCkEditorConfiguration instanceof CKEditorConfigurationInterface) {
75 -
            @trigger_error(sprintf(
76 -
                'Passing %s as argument 1 to %s() is deprecated since sonata-project/formatter-bundle 4.3'
77 -
                .' and will throw a \TypeError in version 5.0. You must pass an instance of %s instead.',
78 -
                \get_class($configManagerOrCkEditorConfiguration),
79 -
                __METHOD__,
80 -
                CKEditorConfigurationInterface::class
81 -
            ), \E_USER_DEPRECATED);
82 -
83 -
            if (!$configManagerOrCkEditorConfiguration instanceof ConfigManagerInterface) {
84 -
                throw new \TypeError(sprintf(
85 -
                    'Argument 3 passed to %s() must be an instance of %s or %s, %s given.',
86 -
                    __METHOD__,
87 -
                    CKEditorConfigurationInterface::class,
88 -
                    ConfigManagerInterface::class,
89 -
                    \get_class($configManagerOrCkEditorConfiguration)
90 -
                ));
91 -
            }
92 -
93 -
            $this->configManager = $configManagerOrCkEditorConfiguration;
94 -
        } else {
95 -
            $this->ckEditorConfiguration = $configManagerOrCkEditorConfiguration;
96 -
        }
97 -
98 -
        $this->pluginManager = $pluginManager;
99 -
        $this->templateManager = $templateManager;
100 -
        $this->stylesSetManager = $stylesSetManager;
101 -
        $this->toolbarManager = $toolbarManager;
102 -
    }
103 -
104 24
    public function buildView(FormView $view, FormInterface $form, array $options): void
105 25
    {
106 -
        if (null !== $this->ckEditorConfiguration) {
107 -
            $defaultConfig = $this->ckEditorConfiguration->getDefaultConfig();
108 -
            $ckeditorConfiguration = $this->ckEditorConfiguration->getConfig($defaultConfig);
109 -
        } else {//NEXT_MAJOR: Remove this case
110 -
            $defaultConfig = $this->configManager->getDefaultConfig();
111 -
112 -
            if ($this->configManager->hasConfig($defaultConfig)) {
113 -
                $ckeditorConfiguration = $this->configManager->getConfig($defaultConfig);
114 -
            } else {
115 -
                $ckeditorConfiguration = [];
116 -
            }
117 -
        }
118 -
119 -
        if (!\array_key_exists('toolbar', $ckeditorConfiguration)) {
120 -
            $ckeditorConfiguration['toolbar'] = array_values($options['ckeditor_toolbar_icons']);
121 -
        }
122 -
123 -
        if ($options['ckeditor_context']) {
124 -
            if (null !== $this->configManager) {//NEXT_MAJOR: Remove this case
125 -
                $contextConfig = $this->configManager->getConfig($options['ckeditor_context']);
126 -
            } else {
127 -
                $contextConfig = $this->ckEditorConfiguration->getConfig($options['ckeditor_context']);
128 -
            }
129 -
130 -
            $ckeditorConfiguration = array_merge($ckeditorConfiguration, $contextConfig);
131 -
        }
132 -
133 -
        if ($options['ckeditor_image_format']) {
134 -
            $ckeditorConfiguration['filebrowserImageUploadRouteParameters']['format'] = $options['ckeditor_image_format'];
135 -
        }
136 -
137 -
        if (null !== $this->ckEditorConfiguration) {
138 -
            $options['ckeditor_plugins'] = $this->ckEditorConfiguration->getPlugins();
139 -
            $options['ckeditor_templates'] = $this->ckEditorConfiguration->getTemplates();
140 -
            $options['ckeditor_style_sets'] = $this->ckEditorConfiguration->getStyles();
141 -
142 -
            if (\is_string($ckeditorConfiguration['toolbar'])) {
143 -
                $ckeditorConfiguration['toolbar'] = $this->ckEditorConfiguration->getToolbar($ckeditorConfiguration['toolbar']);
144 -
            }
145 -
        } else {//NEXT_MAJOR: Remove this case
146 -
            if ($this->pluginManager->hasPlugins()) {
147 -
                $options['ckeditor_plugins'] = $this->pluginManager->getPlugins();
148 -
            }
149 -
150 -
            if ($this->templateManager->hasTemplates()) {
151 -
                $options['ckeditor_templates'] = $this->templateManager->getTemplates();
152 -
            }
153 -
154 -
            if ($this->stylesSetManager->hasStylesSets()) {
155 -
                $options['ckeditor_style_sets'] = $this->stylesSetManager->getStylesSets();
156 -
            } else {
157 -
                $options['ckeditor_style_sets'] = [];
158 -
            }
159 -
160 -
            if (\is_string($ckeditorConfiguration['toolbar'])) {
161 -
                $ckeditorConfiguration['toolbar'] = $this->toolbarManager->resolveToolbar($ckeditorConfiguration['toolbar']);
162 -
            }
163 -
        }
164 -
165 -
        $view->vars['ckeditor_configuration'] = $ckeditorConfiguration;
166 -
        $view->vars['ckeditor_basepath'] = $options['ckeditor_basepath'];
167 -
        $view->vars['ckeditor_plugins'] = $options['ckeditor_plugins'];
168 -
        $view->vars['ckeditor_templates'] = $options['ckeditor_templates'];
169 -
        $view->vars['ckeditor_style_sets'] = $options['ckeditor_style_sets'];
170 -
171 26
        $view->vars['format'] = $options['format'];
172 27
    }
173 28
174 29
    public function configureOptions(OptionsResolver $resolver): void
175 30
    {
176 31
        $resolver->setDefaults([
177 -
            'ckeditor_toolbar_icons' => [[
178 -
                 'Bold', 'Italic', 'Underline',
179 -
                 '-', 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord',
180 -
                 '-', 'Undo', 'Redo',
181 -
                 '-', 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent',
182 -
                 '-', 'Blockquote',
183 -
                 '-', 'Image', 'Link', 'Unlink', 'Table', ],
184 -
                 ['Maximize', 'Source'],
185 -
            ],
186 -
            'ckeditor_basepath' => 'bundles/sonataformatter/vendor/ckeditor',
187 -
            'ckeditor_context' => null,
188 -
            'ckeditor_image_format' => null,
189 -
            'ckeditor_plugins' => [],
190 -
            'ckeditor_templates' => [],
191 32
            'format_options' => [
192 33
                'attr' => [
193 34
                    'class' => 'span10 col-sm-10 col-md-10',

@@ -13,7 +13,6 @@
Loading
13 13
14 14
namespace Sonata\FormatterBundle\DependencyInjection;
15 15
16 -
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
17 16
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
18 17
use Symfony\Component\Config\Definition\ConfigurationInterface;
19 18
@@ -51,26 +50,6 @@
Loading
51 50
                ->end()
52 51
            ->end();
53 52
54 -
        $this->addCkeditorSection($rootNode);
55 -
56 53
        return $treeBuilder;
57 54
    }
58 -
59 -
    private function addCkeditorSection(ArrayNodeDefinition $node): void
60 -
    {
61 -
        $node
62 -
            ->children()
63 -
                ->arrayNode('ckeditor')
64 -
                ->addDefaultsIfNotSet()
65 -
                    ->children()
66 -
                        ->arrayNode('templates')
67 -
                            ->addDefaultsIfNotSet()
68 -
                            ->children()
69 -
                                ->scalarNode('browser')->defaultValue('@SonataFormatter/Ckeditor/browser.html.twig')->cannotBeEmpty()->end()
70 -
                                ->scalarNode('upload')->defaultValue('@SonataFormatter/Ckeditor/upload.html.twig')->cannotBeEmpty()->end()
71 -
                        ->end()
72 -
                    ->end()
73 -
                ->end()
74 -
            ->end();
75 -
    }
76 55
}

@@ -13,7 +13,6 @@
Loading
13 13
14 14
namespace Sonata\FormatterBundle\DependencyInjection;
15 15
16 -
use FOS\CKEditorBundle\Config\CKEditorConfigurationInterface;
17 16
use Sonata\FormatterBundle\Formatter\ExtendableFormatter;
18 17
use Symfony\Component\Config\Definition\Processor;
19 18
use Symfony\Component\Config\FileLocator;
@@ -42,28 +41,17 @@
Loading
42 41
43 42
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
44 43
        $loader->load('formatter.xml');
44 +
        $loader->load('form.xml');
45 45
        $loader->load('twig.xml');
46 46
47 47
        $loader->load('validators.xml');
48 48
49 49
        $bundles = $container->getParameter('kernel.bundles');
50 50
51 -
        if (isset($bundles['FOSCKEditorBundle'])) {
52 -
            if (interface_exists(CKEditorConfigurationInterface::class)) {
53 -
                $loader->load('form.xml');
54 -
            } else {//NEXT_MAJOR: Remove this case
55 -
                $loader->load('form_fcke1.xml');
56 -
            }
57 -
        }
58 -
59 51
        if (isset($bundles['SonataBlockBundle'])) {
60 52
            $loader->load('block.xml');
61 53
        }
62 54
63 -
        if (isset($bundles['SonataMediaBundle'])) {
64 -
            $loader->load('ckeditor.xml');
65 -
        }
66 -
67 55
        if (!\array_key_exists($config['default_formatter'], $config['formatters'])) {
68 56
            throw new \InvalidArgumentException(sprintf(
69 57
                'SonataFormatterBundle - Invalid default formatter: %s, available: %s',
@@ -91,11 +79,6 @@
Loading
91 79
                [$code, new Reference($configuration['service']), $env]
92 80
            );
93 81
        }
94 -
95 -
        $container->setParameter(
96 -
            'sonata.formatter.ckeditor.configuration.templates',
97 -
            $config['ckeditor']['templates']
98 -
        );
99 82
    }
100 83
101 84
    public function getXsdValidationBasePath(): string

Learn more Showing 4 files with coverage changes found.

Changes in src/Extension/GistExtension.php
New
Loading file...
Changes in src/Form/Type/SimpleFormatterType.php
+1
Loading file...
Changes in src/Formatter/Pool.php
-2
+2
Loading file...
Changes in src/Form/Type/FormatterType.php
-29
+32
Loading file...

133 Commits

+24
+24
-1 Files
-3
-3
+1
+1
-1
-1
-29
-1
-28
+2
+1
+1
-2
-1
-1
+2
+1
+1
-2
-1
-1
+2
+1
+1
Hiding 62 contexual commits
-4 Files
-198
-58
-140
Files Complexity Coverage
src ø +3.92% 42.17%
Project Totals (20 files) 141 42.17%
Loading