Drupal 9 image field migration

As you know, when creating image field there is an option to create a default image fallback. Image will be saved in public folder. The issue is that we cant export default image within configs, but that's ok for singlesite instances where you need to manually copy the image to production website from your dev env. Also you need to update the image manually again, if you changed it in configs.

Using https://www.drupal.org/project/config_default_image module will make it possible, but image should be located in public:// folder. Sabe problem again.

My solution is flexible and can use one image for all cases. I had to implement this because of multisite instance, where every website has own files and database, but the same codebase. 
We need to create custom formatter and provide image from module's folder. To achieve this we will use really old ongoing issue to implement additional stream wrappers for D10. Patching the core with https://www.drupal.org/files/issues/2021-12-15/1308152-395.patch will help to achieve the result. Issue url https://www.drupal.org/project/drupal/issues/1308152. It will add additional stream wrappers like module:// and theme://.
So after patching you need to create a custom Formatter to handle default images from your module. Actually it's possible to use an image from custom theme folder but additional settings should be implemented.
Add the image to my_module/images/default-image.png folder and select new formatter for your image.

Code posted on Gists ImageDefaultFallbackFormatter.php

Add new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed.
CAPTCHA
 ooooo      ooo                .oooooo.       oooooooooooo   .o8              .o.       
`888b. `8' d8P' `Y8b `888' `8 "888 .888.
8 `88b. 8 .oooooooo 888 888 888 888oooo. .8"888.
8 `88b. 8 888' `88b 888 888 888oooo8 d88' `88b .8' `888.
8 `88b.8 888 888 888 888 888 " 888 888 .88ooo8888.
8 `888 `88bod8P' `88b d88b 888 888 888 .8' `888.
o8o `8 `8oooooo. `Y8bood8P'Ybd' o888o `Y8bod8P' o88o o8888o
d" YD
"Y88888P'
Enter the code depicted in ASCII art style.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.