Open ThomasCarbon opened 1 year ago
@norkunas done :)
In publish update function, i just changed :
$context = $options['normalization_context'] ?? $this->resourceMetadataFactory->create($resourceClass)->getOperation()->getNormalizationContext() ?? [];
TO
$originalContext = $context ?? ['groups' => []];
$context["groups"] = is_array($iri) ? array_unique(array_merge($iri['context']['groups'], $originalContext['groups'])) : $originalContext['groups'];
$iri = is_array($iri) ? $iri['topics'] : $iri;
Since my change, default entity context were not used while overriding context by topics
Duplicate: https://github.com/api-platform/core/issues/4326
Since the original authord can't reopon the issue even after i added "temporary" solution. I post my own issue.
Here is the repost of my comment in the older issue :
I had the same problem and i managed to made something work. Disclaimer : this is not unit tested since it has been done under an end of a project like "oh shit, this is not natively possible". This is a dirty implementation probably but a good track on how to achieve it in a proper version. But we use it in production since somes weeks now, and it work like a charm. So we did a complete override of
ApiPlatform\Doctrine\EventListener\PublishMercureUpdatesListener
with the following code.Basically, only
storeObjectToPublish()
andpublishUpdate()
had changed. And we added those two function to avoid duplicate code :groupIri()
andgroupIriByTopicContext()
Then inside service.yaml :
Then inside a mercure option its simple :
Note that you can mix whatever you want, it is totally working with the traditional way if for some topics, serialization group are not needed. For example :
Basically, the change just look at the array entry, if its a string it does the old way, if its an array, it look for an 'iri' key and a 'context' key. We use it to always publish complete object to admin iri and the default context of the object to users. Feel free to ask any question and also feel free to improve our shit haha. But at least it works great.
Originally posted by @ThomasCarbon in https://github.com/api-platform/core/issues/4326#issuecomment-1812516742