Skip to content

[feat] Mercure doesn't use state provider when publishing updates #7087

@divine

Description

@divine

API Platform version(s) affected: 4.1.7

Description
Mercure doesn't use entity's state provider when publishing updates

How to reproduce

Let's say you've this in your operations:

new Get(
    provider: ExampleProvider::class,
),

and your ExampleProvider returns a calculated field or extra data from another database.

Mercure publish update listener simply doesn't take into account entity's provider.

Possible Solution

Looks like it's only supports seriliazer:

$resourceClass = $this->getObjectClass($object);
$context = $options['normalization_context'] ?? $this->resourceMetadataFactory->create($resourceClass)->getOperation()->getNormalizationContext() ?? [];
// We need to evaluate it here, because in storeObjectToPublish() the resource would not have been persisted yet
$this->evaluateTopics($options, $object);
$iri = $options['topics'] ?? $this->iriConverter->getIriFromResource($object, UrlGeneratorInterface::ABS_URL);
$data = $options['data'] ?? $this->serializer->serialize($object, key($this->formats), $context);

Additional Context

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions