Unverified Commit 21b8871a authored by jibran's avatar jibran Committed by jibran

Issue #2970836 by jibran, das-peter, Berdir: Argument 3 passed to...

Issue #2970836 by jibran, das-peter, Berdir: Argument 3 passed to Drupal\hal\Normalizer\EntityReferenceItemNormalizer::__construct() must implement interface Drupal\Core\Entity\EntityTypeManagerInterface or be null
parent 88e83199
......@@ -4,6 +4,7 @@ namespace Drupal\dynamic_entity_reference;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Drupal\dynamic_entity_reference\Normalizer\DynamicEntityReferenceItemNormalizer;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
......@@ -17,17 +18,20 @@ class DynamicEntityReferenceServiceProvider extends ServiceProviderBase {
*/
public function alter(ContainerBuilder $container) {
$modules = $container->getParameter('container.modules');
if (isset($modules['rest']) && isset($modules['serialization']) && isset($modules['hal'])) {
if (isset($modules['hal'])) {
// Hal module is enabled, add our new normalizer for dynamic entity
// reference items.
// To avoid problems the arguments to
// \Drupal\hal\Normalizer\EntityReferenceItemNormalizer change, re-use
// the same constructor arguments and set the additional dependency
// with a setter method.
$parent_definition = $container->getDefinition('serializer.normalizer.entity_reference_item.hal');
$service_definition = new Definition(DynamicEntityReferenceItemNormalizer::class, $parent_definition->getArguments());
// Add a normalizer service for dynamic_entity_reference fields.
$service_definition = new Definition('Drupal\dynamic_entity_reference\Normalizer\DynamicEntityReferenceItemNormalizer', [
new Reference('rest.link_manager'),
new Reference('serializer.entity_resolver'),
new Reference('module_handler'),
]);
// The priority must be higher than that of
// serializer.normalizer.entity_reference.hal in hal.services.yml.
$service_definition->addTag('normalizer', ['priority' => 20]);
// serializer.normalizer.entity_reference_item.hal in
// hal.services.yml.
$service_definition->addTag('normalizer', array('priority' => $parent_definition->getTags()['normalizer'][0]['priority'] + 1));
$container->setDefinition('serializer.normalizer.entity.dynamic_entity_reference_item.hal', $service_definition);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment