@@ -190,35 +190,15 @@ private function storeObjectToPublish(object $object, string $property): void
190
190
191
191
$ options ['enable_async_update ' ] ??= true ;
192
192
193
- if ($ options ['topics ' ] ?? false ) {
194
- $ topics = [];
195
- foreach ((array ) $ options ['topics ' ] as $ topic ) {
196
- if (!\is_string ($ topic )) {
197
- $ topics [] = $ topic ;
198
- continue ;
199
- }
200
-
201
- if (!str_starts_with ($ topic , '@= ' )) {
202
- $ topics [] = $ topic ;
203
- continue ;
204
- }
205
-
206
- if (null === $ this ->expressionLanguage ) {
207
- throw new \LogicException ('The "@=" expression syntax cannot be used without the Expression Language component. Try running "composer require symfony/expression-language". ' );
208
- }
209
-
210
- $ topics [] = $ this ->expressionLanguage ->evaluate (substr ($ topic , 2 ), ['object ' => $ object ]);
211
- }
212
-
213
- $ options ['topics ' ] = $ topics ;
214
- }
215
-
216
193
if ('deletedObjects ' === $ property ) {
217
194
$ types = $ operation instanceof HttpOperation ? $ operation ->getTypes () : null ;
218
195
if (null === $ types ) {
219
196
$ types = [$ operation ->getShortName ()];
220
197
}
221
198
199
+ // We need to evaluate it here, because in publishUpdate() the resource would be already deleted
200
+ $ this ->evaluateTopics ($ options , $ object );
201
+
222
202
$ this ->deletedObjects [(object ) [
223
203
'id ' => $ this ->iriConverter ->getIriFromResource ($ object ),
224
204
'iri ' => $ this ->iriConverter ->getIriFromResource ($ object , UrlGeneratorInterface::ABS_URL ),
@@ -244,6 +224,9 @@ private function publishUpdate(object $object, array $options, string $type): vo
244
224
$ resourceClass = $ this ->getObjectClass ($ object );
245
225
$ context = $ options ['normalization_context ' ] ?? $ this ->resourceMetadataFactory ->create ($ resourceClass )->getOperation ()->getNormalizationContext () ?? [];
246
226
227
+ // We need to evaluate it here, because in storeObjectToPublish() the resource would not have been persisted yet
228
+ $ this ->evaluateTopics ($ options , $ object );
229
+
247
230
$ iri = $ options ['topics ' ] ?? $ this ->iriConverter ->getIriFromResource ($ object , UrlGeneratorInterface::ABS_URL );
248
231
$ data = $ options ['data ' ] ?? $ this ->serializer ->serialize ($ object , key ($ this ->formats ), $ context );
249
232
}
@@ -260,6 +243,32 @@ private function publishUpdate(object $object, array $options, string $type): vo
260
243
}
261
244
}
262
245
246
+ private function evaluateTopics (array &$ options , object $ object ): void
247
+ {
248
+ if ($ options ['topics ' ] ?? false ) {
249
+ $ topics = [];
250
+ foreach ((array ) $ options ['topics ' ] as $ topic ) {
251
+ if (!\is_string ($ topic )) {
252
+ $ topics [] = $ topic ;
253
+ continue ;
254
+ }
255
+
256
+ if (!str_starts_with ($ topic , '@= ' )) {
257
+ $ topics [] = $ topic ;
258
+ continue ;
259
+ }
260
+
261
+ if (null === $ this ->expressionLanguage ) {
262
+ throw new \LogicException ('The "@=" expression syntax cannot be used without the Expression Language component. Try running "composer require symfony/expression-language". ' );
263
+ }
264
+
265
+ $ topics [] = $ this ->expressionLanguage ->evaluate (substr ($ topic , 2 ), ['object ' => $ object ]);
266
+ }
267
+
268
+ $ options ['topics ' ] = $ topics ;
269
+ }
270
+ }
271
+
263
272
/**
264
273
* @return Update[]
265
274
*/
0 commit comments