- π©πͺGermany woldtwerk Stralibu
What do I need to do to write my own enhancer in a custom module? Specifically how do I register them?
- π―π΅Japan ptmkenny
@woldtwerk Custom field enhancers should be saved as
/my_module/src/Plugin/jsonapi/FieldEnhancer/MyFieldEnhancer.php
.After that, rebuilding the Drupal cache (drush cr) should cause the field enhancer to be picked up automatically.
- πΊπΈUnited States ndewhurst USA
I successfully set up an enhancer just now by referencing the other ones in code and reading this issue. I just wanted to second the observation in #4 that
doTransform
anddoUndoTransform
seem to be named the opposite of what they do.doUndoTransform
is where you will want to modify the data for API output. I didn't dig around too much to figure out why, but I guess it has to do with the more general intent ofShaper\DataAdaptor\DataAdaptorTransformerTrait
frome0ipso/shaper
, wheredoTransform
is meant to transform "incoming" data, anddoUndoTransform
is meant to perform the inverse transformation on "outgoing" data. Our use cases in this issue are all for outgoing data. At least that's my interpretation.