Documentation for Field Enhancers

Created on 17 May 2019, over 5 years ago
Updated 4 April 2024, 9 months ago

I can't find any documentation for creating custom field enhancers.

I was looking at creating one that would change the photo reference to the url of the photo. I don't see any clear documentation and have been attempting to create something like this just by looking at the source code but it's proving challenging.

Some documented examples/tutorials/guidelines for creating these in your own module would be helpful!

πŸ“Œ Task
Status

Active

Version

3.0

Component

Documentation

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺ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.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • πŸ‡ΊπŸ‡Έ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 and doUndoTransform 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 of Shaper\DataAdaptor\DataAdaptorTransformerTrait from e0ipso/shaper, where doTransform is meant to transform "incoming" data, and doUndoTransform 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.

Production build 0.71.5 2024