-
Notifications
You must be signed in to change notification settings - Fork 49
Add a post event trigger in the renderEntity method of the Hal plugin #46
Comments
Question: why can you not modify the entity during the original event? We pass the As such, you can do your modifications already within the event... unless I'm missing something. Can you elaborate on what you're trying to do, please? |
For certain properties of a Doctrine entity I add a custom hydrator strategy called "HiddenStrategy". This strategy converts the value of the property to "_ HIDDEN _". At the moment I have the class extended with this method:
I unset the keys that have _ HIDDEN _ as value. Because this is the latest place before output. At the moment there is only a trigger at the beginning of the method. But there the HAL entity still holds a Doctrine entity and strategies are not applied yet. So at the end of the method I have a nice array that I can modify just before output. |
Why not have your hydrator simply not return those properties, instead of marking them as |
How would I do that? The hydrator strategies work on a specific field. I don't want to create a custom hydrator class for every rest service. It's a breeze to just use the default phpro abstract hydrator and configure strategies for the hydrator in the module.config.php file of some API module. My current class is:
If I return nothing in the extract method the property will still be available, but will just have a NULL value. |
This is now available on the develop branch; you can pin composer to use zf-hal with versions |
The renderEntity method of the \ZF\Hal\Plugin\Hal plugin triggers an event on the first line of that method. It would be very nice if an event is also triggered add the bottom of that method, just before the entity is returned.
That way I can modifiy some data in the array before it's returned.
The text was updated successfully, but these errors were encountered: