Skip to content

Commit

Permalink
[Extraction] Added kernel 7.x compatibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bertrand Dunogier committed Mar 28, 2018
1 parent cd920c9 commit edc7e2a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/bundle/DependencyInjection/Compiler/KernelRichTextPass.php
@@ -0,0 +1,60 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformRichTextFieldTypeBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
* Handles compatibility with kernel 7.x.
*/
class KernelRichTextPass implements CompilerPassInterface
{
private $servicesToRemove = [
'ezpublish.fieldType.ezrichtext',
'ezpublish.fieldType.ezrichtext.converter',
'ezpublish.fieldType.indexable.ezrichtext',
'ezpublish_rest.field_type_processor.ezrichtext',
'EzSystems\\RepositoryForms\\FieldType\\Mapper\\RichTextFormMapper',
];

public function process(ContainerBuilder $container)
{
array_map(
function ($service) use ($container) {
if ($container->hasDefinition($service)) {
$container->log($this, "Removed ezpublish-kernel richtext service: $service");
$container->removeDefinition($service);
}
},
$this->servicesToRemove
);

$def = $container->getDefinition('ezpublish.persistence.legacy.field_value_converter.registry');
$methodCalls = [];
foreach ($def->getMethodCalls() as $methodCall) {
if ($methodCall[0] != 'register') {
$methodCalls[] = $methodCall;
continue;
}

if ($methodCall[1][0] != 'ezrichtext') {
$methodCalls[] = $methodCall;
continue;
}

if (!$methodCall[1][1] instanceof Reference || (string)$methodCall[1][1] !== 'ezpublish.fieldType.ezrichtext.converter') {
$methodCalls[] = $methodCall;
continue;
}
}
$def->setMethodCalls($methodCalls);
}
}
1 change: 1 addition & 0 deletions src/bundle/EzPlatformRichTextFieldTypeBundle.php
Expand Up @@ -25,6 +25,7 @@ public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new RichTextHtml5ConverterPass());
$container->addCompilerPass(new KernelRichTextPass());
$this->registerConfigParser($container);
}

Expand Down
1 change: 1 addition & 0 deletions tests/integration/eZ/API/LegacySetupFactory.php
Expand Up @@ -32,6 +32,7 @@ protected function externalBuildContainer(ContainerBuilder $containerBuilder)
$loader->load('storage_engines/legacy/external_storage_gateways.yml');
$loader->load('storage_engines/legacy/field_value_converters.yml');

$containerBuilder->addCompilerPass(new Compiler\KernelRichTextPass());
$containerBuilder->addCompilerPass(new Compiler\RichTextHtml5ConverterPass());
}
}

0 comments on commit edc7e2a

Please sign in to comment.