Calling ThemeInstaller::install() within hook_install can fail

Created on 25 August 2016, almost 8 years ago
Updated 18 January 2024, 5 months ago

A common scenario for sitebuilders is to use modules (such as Features) to store configuration for their site, including to enable and set default themes. For instance, you might have this in your module .install file:

/**
  * Implements hook_install().
  */
function foo_install() {
  // Enable and set default theme.
  \Drupal::service('theme_installer')->install(array('my_theme'), TRUE);
  \Drupal::configFactory()->getEditable('system.theme')->set('default', 'my_theme')->save(TRUE);
}

This seems to work fine most of the time. However, I've identified at least one scenario where it can fail without any warning: if the calling module is installed as a dependency of another module rather than being installed directly.

To reproduce this, add the code above to a custom module (call it module 'Foo'), adjusting the theme name to reflect an available but uninstalled theme. Enable Foo via the Module UI, and note that the theme is installed. Now re-install your site, and create another custom module ('Bar') that depends on Foo. Install Bar. Note that while Foo gets installed, the theme is not installed.

🐛 Bug report
Status

Closed: cannot reproduce

Version

9.4

Component
Extension 

Last updated 3 days ago

No maintainer
Created by

🇺🇸United States Dane Powell

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.

  • 🇮🇳India Rajeshreeputra Pune

    [error]
    TypeError: Drupal\system\PathBasedBreadcrumbBuilder::__construct(): Argument #7 ($request_generator) must be of type Drupal\system\RequestGenerator|Drupal\Core\Session\AccountInterface, Drupal\Core\Utility\RequestGenerator given, called in /docroot/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 in Drupal\system\PathBasedBreadcrumbBuilder->__construct() (line 116 of /docroot/core/modules/system/src/PathBasedBreadcrumbBuilder.php) #0 /docroot/core/lib/Drupal/Component/DependencyInjection/Container.php(259): Drupal\system\PathBasedBreadcrumbBuilder->__construct()

    Trace:
    /modules/acquia_cms_common/acquia_cms_common.install(36): Drupal\Core\Extension\ThemeInstaller->install()
    # [internal function]: acquia_cms_common_install()
    https://git.drupalcode.org/project/acquia_cms_common/-/blob/3.x/acquia_c...

Production build 0.69.0 2024