is there some solution how to filter value/values with Symfony Event Dispatcher like wordpress with add_filter that returns filtered value? Maybe store properties in Event and edit them with subscriber?
Asked
Active
Viewed 266 times
-2
-
Working both in Symfony and WordPress and having experience with Joomla filtering plugins, I understand your question, and in fact I already answered, but a Symfony dev with less experienced with filters would probably have a hard time understand. You should probably expand the description of what you need to achieve. – Francesco Abeni Nov 09 '20 at 10:41
1 Answers
0
The solution you proposed is the best I can think of. There is no "native" mechanism intended to post-process a value like in WordPress filters or Joomla plugins.
If you dispatch a custom event and populate with the object you want to "filter" you can easily add a subscriber to do what you mean. As objects are always passed by reference, any alteration to the object will be propagated in the controller.
E.g.
controller:
$product = $this->productRepository->get($someId);
$this->eventDispacther->dispatch(
BeforeDisplayEvent::class,
new BeforeDisplayEvent($product)
)
return $this->render('product.html.twig', ['product' => $product]);
subscriber:
public function alterProduct(BeforeDisplayEvent $event)
{
$product->setSomething($this->yourFilter($product));
}

Francesco Abeni
- 4,190
- 1
- 19
- 30
-
1I see that you are a Joomla developer, but you have not extended your Stack Exchange citizenship to [joomla.se] Stack Exchange. Please join us and help us to resolve some of our unresolved questions. – mickmackusa Nov 10 '20 at 05:41
-
@mickmackusa thank you. I joined it but I cannot guarantee I'll have the time / skill to resolve unresolved questions :-) – Francesco Abeni Nov 10 '20 at 09:17
-