DynamicEntityReferenceServiceProvider.php in Dynamic Entity Reference 8.2
File
src/DynamicEntityReferenceServiceProvider.php
View source
<?php
namespace Drupal\dynamic_entity_reference;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Drupal\Core\Entity\Query\Sql\QueryFactory as BaseQueryFactory;
use Drupal\Core\Entity\Query\Sql\pgsql\QueryFactory as BasePgsqlQueryFactory;
use Drupal\dynamic_entity_reference\Normalizer\DynamicEntityReferenceItemNormalizer;
use Drupal\dynamic_entity_reference\Query\PgsqlQueryFactory;
use Drupal\dynamic_entity_reference\Query\QueryFactory;
use Symfony\Component\DependencyInjection\Definition;
class DynamicEntityReferenceServiceProvider extends ServiceProviderBase {
public function alter(ContainerBuilder $container) {
$modules = $container
->getParameter('container.modules');
if (isset($modules['hal'])) {
$parent_definition = $container
->getDefinition('serializer.normalizer.entity_reference_item.hal');
$service_definition = new Definition(DynamicEntityReferenceItemNormalizer::class, $parent_definition
->getArguments());
$service_definition
->addTag('normalizer', [
'priority' => $parent_definition
->getTags()['normalizer'][0]['priority'] + 1,
]);
$container
->setDefinition('serializer.normalizer.entity.dynamic_entity_reference_item.hal', $service_definition);
}
$map = [
'entity.query.sql' => [
'old' => BaseQueryFactory::class,
'new' => QueryFactory::class,
],
'pgsql.entity.query.sql' => [
'old' => BasePgsqlQueryFactory::class,
'new' => PgsqlQueryFactory::class,
],
];
foreach ($map as $service_id => $data) {
if ($container
->hasDefinition($service_id)) {
$service_definition = $container
->getDefinition($service_id);
if ($service_definition
->getClass() == $data['old']) {
$service_definition
->setClass($data['new']);
$container
->setDefinition($service_id, $service_definition);
}
}
}
}
}