Loading flow.info.yml +1 −1 Original line number Diff line number Diff line type: module name: "Flow (automation)" description: "Automates your workflow on content." core_version_requirement: ^9 || ^10 core_version_requirement: ^9.4 || ^10 package: Other configure: flow.settings dependencies: Loading flow.services.yml +3 −0 Original line number Diff line number Diff line Loading @@ -43,3 +43,6 @@ services: calls: - [setDecoratedNormalizer, ['@serializer.normalizer.flow__entity_reference_field_item.inner']] - [setEntityTypeManager, ['@entity_type.manager']] flow.normalizer_container: class: Drupal\flow\Internals\NormalizerContainer arguments: ['@serializer.normalizer.flow__content_entity', '@serializer.normalizer.flow__entity_reference_field_item'] src/FlowServiceProvider.php 0 → 100644 +27 −0 Original line number Diff line number Diff line <?php namespace Drupal\flow; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderBase; /** * Provider for dynamically provided services by Flow. */ class FlowServiceProvider extends ServiceProviderBase { /** * {@inheritdoc} */ public function alter(ContainerBuilder $container): void { [$version] = explode('.', \Drupal::VERSION, 2); if (((int) $version) < 10) { // Use normalizers that are compatible with Symfony 4. $definition = $container->getDefinition('serializer.normalizer.flow__content_entity'); $definition->setClass('Drupal\flow\Normalizer\Legacy\FlowContentEntityNormalizer'); $definition = $container->getDefinition('serializer.normalizer.flow__entity_reference_field_item'); $definition->setClass('Drupal\flow\Normalizer\Legacy\FlowEntityReferenceFieldItemNormalizer'); } } } src/Helpers/EntitySerializationTrait.php +11 −10 Original line number Diff line number Diff line Loading @@ -3,8 +3,7 @@ namespace Drupal\flow\Helpers; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\flow\Normalizer\FlowContentEntityNormalizer; use Drupal\flow\Normalizer\FlowEntityReferenceFieldItemNormalizer; use Drupal\flow\Internals\NormalizerContainer; use Symfony\Component\Serializer\Serializer; /** Loading Loading @@ -87,14 +86,15 @@ trait EntitySerializationTrait { * The normalized array. */ public function toConfigArray(ContentEntityInterface $entity): array { FlowContentEntityNormalizer::$cleanupFieldValues = TRUE; FlowEntityReferenceFieldItemNormalizer::$normalizeNewEntities = TRUE; $normalizer_container = NormalizerContainer::get(); $normalizer_container->contentEntityNormalizer()::$cleanupFieldValues = TRUE; $normalizer_container->entityReferenceItemNormalizer()::$normalizeNewEntities = TRUE; try { return $this->getSerializer()->normalize($entity, get_class($entity)); } finally { FlowContentEntityNormalizer::$cleanupFieldValues = FALSE; FlowEntityReferenceFieldItemNormalizer::$normalizeNewEntities = FALSE; $normalizer_container->contentEntityNormalizer()::$cleanupFieldValues = FALSE; $normalizer_container->entityReferenceItemNormalizer()::$normalizeNewEntities = FALSE; } } Loading @@ -110,14 +110,15 @@ trait EntitySerializationTrait { * The entity. */ public function fromConfigArray(array $array, string $entity_class): ContentEntityInterface { FlowContentEntityNormalizer::$cleanupFieldValues = TRUE; FlowEntityReferenceFieldItemNormalizer::$normalizeNewEntities = TRUE; $normalizer_container = NormalizerContainer::get(); $normalizer_container->contentEntityNormalizer()::$cleanupFieldValues = TRUE; $normalizer_container->entityReferenceItemNormalizer()::$normalizeNewEntities = TRUE; try { return $this->getSerializer()->denormalize($array, $entity_class); } finally { FlowContentEntityNormalizer::$cleanupFieldValues = FALSE; FlowEntityReferenceFieldItemNormalizer::$normalizeNewEntities = FALSE; $normalizer_container->contentEntityNormalizer()::$cleanupFieldValues = FALSE; $normalizer_container->entityReferenceItemNormalizer()::$normalizeNewEntities = FALSE; } } Loading src/Internals/NormalizerContainer.php 0 → 100644 +72 −0 Original line number Diff line number Diff line <?php namespace Drupal\flow\Internals; /** * Contains serialization normalizers provided by the Flow module. * * Normalizers are private services. However, flags need to be set from * elsewhere on these normalizers. To get them, this class exists as a wrapper. * * @internal This class is not meant for API usage and is subject to change. */ final class NormalizerContainer { /** * The content entity normalizer. * * @var mixed */ private $contentEntityNormalizer; /** * The entity reference item normalizer. * * @var mixed */ private $entityReferenceItemNormalizer; /** * Get the service instance of this class. * * @return \Drupal\flow\Internals\NormalizerContainer * The service instance. */ public static function get(): NormalizerContainer { return \Drupal::service('flow.normalizer_container'); } /** * The NormalizerContainer constructor. * * @param mixed $content_entity_normalizer * The content entity normalizer. * @param mixed $entity_reference_item_normalizer * The entity reference item normalizer. */ public function __construct($content_entity_normalizer, $entity_reference_item_normalizer) { $this->contentEntityNormalizer = $content_entity_normalizer; $this->entityReferenceItemNormalizer = $entity_reference_item_normalizer; } /** * Get the content entity normalizer. * * @return mixed * The content entity normalizer. */ public function contentEntityNormalizer() { return $this->contentEntityNormalizer; } /** * Get the entity reference item normalizer. * * @return mixed * The entity reference item normalizer. */ public function entityReferenceItemNormalizer() { return $this->entityReferenceItemNormalizer; } } Loading
flow.info.yml +1 −1 Original line number Diff line number Diff line type: module name: "Flow (automation)" description: "Automates your workflow on content." core_version_requirement: ^9 || ^10 core_version_requirement: ^9.4 || ^10 package: Other configure: flow.settings dependencies: Loading
flow.services.yml +3 −0 Original line number Diff line number Diff line Loading @@ -43,3 +43,6 @@ services: calls: - [setDecoratedNormalizer, ['@serializer.normalizer.flow__entity_reference_field_item.inner']] - [setEntityTypeManager, ['@entity_type.manager']] flow.normalizer_container: class: Drupal\flow\Internals\NormalizerContainer arguments: ['@serializer.normalizer.flow__content_entity', '@serializer.normalizer.flow__entity_reference_field_item']
src/FlowServiceProvider.php 0 → 100644 +27 −0 Original line number Diff line number Diff line <?php namespace Drupal\flow; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderBase; /** * Provider for dynamically provided services by Flow. */ class FlowServiceProvider extends ServiceProviderBase { /** * {@inheritdoc} */ public function alter(ContainerBuilder $container): void { [$version] = explode('.', \Drupal::VERSION, 2); if (((int) $version) < 10) { // Use normalizers that are compatible with Symfony 4. $definition = $container->getDefinition('serializer.normalizer.flow__content_entity'); $definition->setClass('Drupal\flow\Normalizer\Legacy\FlowContentEntityNormalizer'); $definition = $container->getDefinition('serializer.normalizer.flow__entity_reference_field_item'); $definition->setClass('Drupal\flow\Normalizer\Legacy\FlowEntityReferenceFieldItemNormalizer'); } } }
src/Helpers/EntitySerializationTrait.php +11 −10 Original line number Diff line number Diff line Loading @@ -3,8 +3,7 @@ namespace Drupal\flow\Helpers; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\flow\Normalizer\FlowContentEntityNormalizer; use Drupal\flow\Normalizer\FlowEntityReferenceFieldItemNormalizer; use Drupal\flow\Internals\NormalizerContainer; use Symfony\Component\Serializer\Serializer; /** Loading Loading @@ -87,14 +86,15 @@ trait EntitySerializationTrait { * The normalized array. */ public function toConfigArray(ContentEntityInterface $entity): array { FlowContentEntityNormalizer::$cleanupFieldValues = TRUE; FlowEntityReferenceFieldItemNormalizer::$normalizeNewEntities = TRUE; $normalizer_container = NormalizerContainer::get(); $normalizer_container->contentEntityNormalizer()::$cleanupFieldValues = TRUE; $normalizer_container->entityReferenceItemNormalizer()::$normalizeNewEntities = TRUE; try { return $this->getSerializer()->normalize($entity, get_class($entity)); } finally { FlowContentEntityNormalizer::$cleanupFieldValues = FALSE; FlowEntityReferenceFieldItemNormalizer::$normalizeNewEntities = FALSE; $normalizer_container->contentEntityNormalizer()::$cleanupFieldValues = FALSE; $normalizer_container->entityReferenceItemNormalizer()::$normalizeNewEntities = FALSE; } } Loading @@ -110,14 +110,15 @@ trait EntitySerializationTrait { * The entity. */ public function fromConfigArray(array $array, string $entity_class): ContentEntityInterface { FlowContentEntityNormalizer::$cleanupFieldValues = TRUE; FlowEntityReferenceFieldItemNormalizer::$normalizeNewEntities = TRUE; $normalizer_container = NormalizerContainer::get(); $normalizer_container->contentEntityNormalizer()::$cleanupFieldValues = TRUE; $normalizer_container->entityReferenceItemNormalizer()::$normalizeNewEntities = TRUE; try { return $this->getSerializer()->denormalize($array, $entity_class); } finally { FlowContentEntityNormalizer::$cleanupFieldValues = FALSE; FlowEntityReferenceFieldItemNormalizer::$normalizeNewEntities = FALSE; $normalizer_container->contentEntityNormalizer()::$cleanupFieldValues = FALSE; $normalizer_container->entityReferenceItemNormalizer()::$normalizeNewEntities = FALSE; } } Loading
src/Internals/NormalizerContainer.php 0 → 100644 +72 −0 Original line number Diff line number Diff line <?php namespace Drupal\flow\Internals; /** * Contains serialization normalizers provided by the Flow module. * * Normalizers are private services. However, flags need to be set from * elsewhere on these normalizers. To get them, this class exists as a wrapper. * * @internal This class is not meant for API usage and is subject to change. */ final class NormalizerContainer { /** * The content entity normalizer. * * @var mixed */ private $contentEntityNormalizer; /** * The entity reference item normalizer. * * @var mixed */ private $entityReferenceItemNormalizer; /** * Get the service instance of this class. * * @return \Drupal\flow\Internals\NormalizerContainer * The service instance. */ public static function get(): NormalizerContainer { return \Drupal::service('flow.normalizer_container'); } /** * The NormalizerContainer constructor. * * @param mixed $content_entity_normalizer * The content entity normalizer. * @param mixed $entity_reference_item_normalizer * The entity reference item normalizer. */ public function __construct($content_entity_normalizer, $entity_reference_item_normalizer) { $this->contentEntityNormalizer = $content_entity_normalizer; $this->entityReferenceItemNormalizer = $entity_reference_item_normalizer; } /** * Get the content entity normalizer. * * @return mixed * The content entity normalizer. */ public function contentEntityNormalizer() { return $this->contentEntityNormalizer; } /** * Get the entity reference item normalizer. * * @return mixed * The entity reference item normalizer. */ public function entityReferenceItemNormalizer() { return $this->entityReferenceItemNormalizer; } }