Is there any way we can change configuration items when we switch to a specific theme?
Our (simplified) situation:
- Using Drupal 10.2
- Our customers can choose between different themes
- Every theme uses content-type 'Page'
- One theme has a background-picture, differing from page to page, uploaded by the editors. So if this theme is chosen, 'Page' needs to have a field 'background-image' (media).
How can I add a field to a content-type when setting this theme as default theme without manual changes in the admin-backend?
What I already tried:
Using
hook_install()
=> This hook only works on modules and not on themes. (https://www.drupal.org/node/2652542). And even if: It would be executed on theme installation and not when it is set as default.Using
config/install
(as mentioned in Is there a theme equivalent of hook_install()?) => This allows me to installfield.storage.node.field_background_picture
andfield.field.node.page.field_background_picture
, but not to add thefield_background_picture
to the already existingcore.entity_form_display.node.page.default
and similar configs - I now have the field, but neither in the form nor in the display.Using
config/optional
=> The same as above. Additions or changes to existing config do not lead to errors, but the changes to the form and view are silently ignored. And even if: It would be executed on theme installation and not when it is set as default.
Thanks in advance and greetings from Switzerland mullzk
hook_form_alter
, is your best bet