public ThemeInstaller::uninstall(array $theme_list)
Uninstalls a given list of themes.
Uninstalling a theme removes all related configuration (like blocks) and invokes the 'themes_uninstalled' hook.
Parameters
array $theme_list: The themes to uninstall.
Throws
\InvalidArgumentException Thrown when you uninstall an not installed theme.
Overrides ThemeInstallerInterface::uninstall
See also
File
- core/lib/Drupal/Core/Extension/ThemeInstaller.php, line 214
Class
- ThemeInstaller
- Manages theme installation/uninstallation.
Namespace
Drupal\Core\Extension
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | public function uninstall( array $theme_list ) { $extension_config = $this ->configFactory->getEditable( 'core.extension' ); $theme_config = $this ->configFactory->getEditable( 'system.theme' ); $list = $this ->themeHandler->listInfo(); foreach ( $theme_list as $key ) { if (!isset( $list [ $key ])) { throw new \InvalidArgumentException( "Unknown theme: $key." ); } if ( $key === $theme_config ->get( 'default' )) { throw new \InvalidArgumentException( "The current default theme $key cannot be uninstalled." ); } if ( $key === $theme_config ->get( 'admin' )) { throw new \InvalidArgumentException( "The current administration theme $key cannot be uninstalled." ); } // Base themes cannot be uninstalled if sub themes are installed, and if // they are not uninstalled at the same time. // @todo https://www.drupal.org/node/474684 and // https://www.drupal.org/node/1297856 themes should leverage the module // dependency system. if (! empty ( $list [ $key ]->sub_themes)) { foreach ( $list [ $key ]->sub_themes as $sub_key => $sub_label ) { if (isset( $list [ $sub_key ]) && !in_array( $sub_key , $theme_list , TRUE)) { throw new \InvalidArgumentException( "The base theme $key cannot be uninstalled, because theme $sub_key depends on it." ); } } } } $this ->cssCollectionOptimizer->deleteAll(); $current_theme_data = $this ->state->get( 'system.theme.data' , array ()); foreach ( $theme_list as $key ) { // The value is not used; the weight is ignored for themes currently. $extension_config ->clear( "theme.$key" ); // Update the current theme data accordingly. unset( $current_theme_data [ $key ]); // Reset theme settings. $theme_settings = &drupal_static( 'theme_get_setting' ); unset( $theme_settings [ $key ]); // Remove all configuration belonging to the theme. $this ->configManager->uninstall( 'theme' , $key ); } // Don't check schema when uninstalling a theme since we are only clearing // keys. $extension_config ->save(TRUE); $this ->state->set( 'system.theme.data' , $current_theme_data ); // @todo Remove system_list(). $this ->themeHandler->refreshInfo(); $this ->resetSystem(); $this ->moduleHandler->invokeAll( 'themes_uninstalled' , [ $theme_list ]); } |
Please login to continue.