Themes support post updates in order to:
- install module dependencies that have been added to the THEME.info.yml after the theme has been installed.
- fix theme settings configuration if a theme has changed its configuration schema
Themes can have a THEME.post_update.php file that, for example, contains an update function that installs an extension.
/**
* Install a dependent module.
*/
function test_theme_depending_on_modules_post_update_module_install(&$sandbox = NULL) {
\Drupal::service('module_installer')->install(['test_another_module_required_by_theme']);
}
This update will then be listed when a user visits update.php and run as part of the update batch. The documentation block preceding this function is stripped of newlines and used as the description for the update on the pending updates task list, which users will see when they run the update.php script.
See HOOK_post_update_NAME() documentation for more information about post updates.
As a result, themes also now support HOOK_removed_post_updates()
.
Note: This feature did not work in 9.4.0-alpha1 for themes that were used for the Drupal installer. It was fixed by #3279850: Theme post updates are not recognised when the theme is used in the installer for the next release.