I have two modules, each of which is defining a normalizer service
module_one.services.yml
services:
module_one.normalizer.node_entity:
class: Drupal\module_one\Normalizer\ModuleOneEntityNormalizer
arguments: ['@entity_type.manager']
tags:
- { name: normalizer, priority: 10 }
module_two.services.yml
services:
module_two.normalizer.node_entity:
class: Drupal\module_two\Normalizer\ModuleTwoEntityNormalizer
arguments: ['@entity_type.manager']
tags:
- { name: normalizer, priority: 10 }
For each module, I am creating a distinct normalizer and presumably defining a separate namespace, ex:
<?php
namespace Drupal\module_one\Normalizer;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\serialization\Normalizer\ContentEntityNormalizer;
use Drupal\node\NodeInterface;
/**
* Converts the Drupal entity object structures to a normalized array.
*/
class ModuleOneEntityNormalizer extends ContentEntityNormalizer {
...
The problem is that with both modules enabled, one service is blocking the other - the serializer / normalizer fires as expected for the first one but not for the second. The only way to get the other one to be recognized is to increase its priority but that blocks the first.
What am I missing in the definitions that would prevent these two services from conflicting with each other?
Update: Thanks for the really helpful comments, starting to dial in on this. Both normalizers have the same protected $supportedInterface, ex:
/**
* The interface or class that this Normalizer supports.
*
* @var string
*/
protected $supportedInterfaceOrClass = [
'Drupal\node\NodeInterface'
];
Which is flagged in the Drupal Serialization API handbook as an issue