|
11 | 11 |
|
12 | 12 | namespace Symfony\Cmf\Bundle\SonataPhpcrAdminIntegrationBundle\DependencyInjection;
|
13 | 13 |
|
| 14 | +use Ivory\CKEditorBundle\IvoryCKEditorBundle; |
| 15 | +use Symfony\Cmf\Bundle\SonataPhpcrAdminIntegrationBundle\DependencyInjection\Factory\IsConfigEnabledTrait; |
14 | 16 | use Symfony\Component\Config\FileLocator;
|
15 | 17 | use Symfony\Component\DependencyInjection\ContainerBuilder;
|
16 | 18 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|
24 | 26 | */
|
25 | 27 | class CmfSonataPhpcrAdminIntegrationExtension extends Extension implements CompilerPassInterface
|
26 | 28 | {
|
| 29 | + use IsConfigEnabledTrait; |
| 30 | + |
27 | 31 | /**
|
28 | 32 | * @var AdminFactoryInterface[]
|
29 | 33 | */
|
@@ -61,6 +65,36 @@ public function load(array $configs, ContainerBuilder $container)
|
61 | 65 |
|
62 | 66 | $loader->load('main.xml');
|
63 | 67 | $loader->load('enhancer.xml');
|
| 68 | + |
| 69 | + $this->loadIvoryCKEditor($config['ivory_ckeditor'], $container); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Adds the ckEditor configuration to the parameters list when configuration is enabled (auto, true). For both |
| 74 | + * settings the "egeloen/ckeditor-bundle" has to be installed and enabled. |
| 75 | + * |
| 76 | + * @param array $config |
| 77 | + * @param ContainerBuilder $container |
| 78 | + * |
| 79 | + * @throws \LogicException when configuration is enabled by true and "IvoryCKEditorBundle" is not enabled |
| 80 | + */ |
| 81 | + protected function loadIvoryCKEditor(array $config, ContainerBuilder $container) |
| 82 | + { |
| 83 | + $configParameter = []; |
| 84 | + if ($this->isConfigEnabled($container, $config)) { |
| 85 | + $bundles = $container->getParameter('kernel.bundles'); |
| 86 | + if (true === $config['enabled'] && !isset($bundles['IvoryCKEditorBundle'])) { |
| 87 | + $message = 'IvoryCKEditorBundle integration was explicitely enabled, but the bundle is not available'; |
| 88 | + if (class_exists(IvoryCKEditorBundle::class)) { |
| 89 | + $message .= ' (did you forget to register the bundle in the AppKernel?)'; |
| 90 | + } |
| 91 | + throw new \LogicException($message.'.'); |
| 92 | + } elseif (isset($bundles['IvoryCKEditorBundle'])) { |
| 93 | + $configParameter = ['config_name' => $config['config_name']]; |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + $container->setParameter('cmf_sonata_phpcr_admin_integration.ivory_ckeditor.config', $configParameter); |
64 | 98 | }
|
65 | 99 |
|
66 | 100 | /**
|
|
0 commit comments