0

Working

  1. We have a custom base theme.
  2. There are custom theme settings with default values.
  3. When the theme is initially installed, the theme settings are correctly set as default. Good.
  4. This custom base theme is now on our many live sites.

Not working

  1. We added a new custom theme setting to the base theme, and set a default value.
  2. When we update the base theme on a site, the new theme setting is there. Good.
  3. However, the default value is not filled in.

Question How do I set the default value of a new theme setting when the theme is updated?

3

From what I can tell, themes do not process update hooks since they do not have a schema value tracked in the key_value table. So a hook_update_N is not possible in this case.

This means that you have a couple of options.

Option 1

If the theme is going to be updated in code, but not updated right away through the UI form, you will probably want run a drush command as part of the theme update.

drush config-set THEME.settings NEW_SETTING NEW_SETTING_VALUE'

Reference: https://drushcommands.com/drush-8x/config/config-set/

This will allow you to set it once and then any future updates/overrides can be handled as usual through the configuration system.

Option 2

If you are talking about a theme that is part of a distribution, and you don't have access to the system to run the drush command, then you could set a default value on the hook_form_system_theme_settings_alter function. This would not provide the value to the system when it loads the config, but it would provide a default to users when they update the theme and save the settings form.

If you did it that way, you would need to provide a fallback in your theme for if/when that value is not present to prevent unexpected behavior if the new setting value isn't yet set in the site's settings file.

Option 3

If you have access to the codebases for the affected systems, like in a site factory, then you could technically provide the new value in the exported configuration file itself and then it would be picked up upon config import.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.