class ThemeInstaller implements ThemeInstallerInterface (View source)

Manages theme installation/uninstallation.

Traits

Messages for missing or incompatible dependencies on modules.

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected ThemeHandlerInterface $themeHandler
protected ConfigFactoryInterface $configFactory
protected ConfigInstallerInterface $configInstaller
protected ModuleHandlerInterface $moduleHandler
protected StateInterface $state
protected ConfigManagerInterface $configManager
protected AssetCollectionOptimizerInterface $cssCollectionOptimizer
protected RouteBuilderInterface $routeBuilder
protected LoggerInterface $logger
protected ModuleExtensionList $moduleExtensionList

The module extension list.

Methods

string|null
checkDependencyMessage(array $modules, string $dependency, Dependency $dependency_object)

Provides messages for missing modules or incompatible dependencies.

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__construct(ThemeHandlerInterface $theme_handler, ConfigFactoryInterface $config_factory, ConfigInstallerInterface $config_installer, ModuleHandlerInterface $module_handler, ConfigManagerInterface $config_manager, AssetCollectionOptimizerInterface $css_collection_optimizer, RouteBuilderInterface $route_builder, LoggerInterface $logger, StateInterface $state, ModuleExtensionList $module_extension_list = NULL)

Constructs a new ThemeInstaller.

bool
install(array $theme_list, bool $install_dependencies = TRUE)

Installs a given list of themes.

uninstall(array $theme_list)

Uninstalls a given list of themes.

resetSystem()

Resets some other systems like rebuilding the route information or caches.

themeRegistryRebuild()

Wraps drupal_theme_rebuild().

Details

string|null checkDependencyMessage(array $modules, string $dependency, Dependency $dependency_object)

Provides messages for missing modules or incompatible dependencies.

Parameters

array $modules

The list of existing modules.

string $dependency

The module dependency to check.

Dependency $dependency_object

Dependency object used for comparing version requirement data.

Return Value

string|null

NULL if compatible, otherwise a string describing the incompatibility.

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__construct(ThemeHandlerInterface $theme_handler, ConfigFactoryInterface $config_factory, ConfigInstallerInterface $config_installer, ModuleHandlerInterface $module_handler, ConfigManagerInterface $config_manager, AssetCollectionOptimizerInterface $css_collection_optimizer, RouteBuilderInterface $route_builder, LoggerInterface $logger, StateInterface $state, ModuleExtensionList $module_extension_list = NULL)

Constructs a new ThemeInstaller.

Parameters

ThemeHandlerInterface $theme_handler

The theme handler.

ConfigFactoryInterface $config_factory

The config factory to get the installed themes.

ConfigInstallerInterface $config_installer

(optional) The config installer to install configuration. This optional to allow the theme handler to work before Drupal is installed and has a database.

ModuleHandlerInterface $module_handler

The module handler to fire themes_installed/themes_uninstalled hooks.

ConfigManagerInterface $config_manager

The config manager used to uninstall a theme.

AssetCollectionOptimizerInterface $css_collection_optimizer

The CSS asset collection optimizer service.

RouteBuilderInterface $route_builder

(optional) The route builder service to rebuild the routes if a theme is installed.

LoggerInterface $logger

A logger instance.

StateInterface $state

The state store.

ModuleExtensionList $module_extension_list

The module extension list.

bool install(array $theme_list, bool $install_dependencies = TRUE)

Installs a given list of themes.

Parameters

array $theme_list

An array of theme names.

bool $install_dependencies

(optional) If TRUE, dependencies will automatically be installed in the correct order. This incurs a significant performance cost, so use FALSE if you know $theme_list is already complete and in the correct order.

Return Value

bool

Whether any of the given themes have been installed.

Exceptions

ExtensionNameLengthException
UnknownExtensionException
MissingDependencyException

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.

Exceptions

UnknownExtensionException
InvalidArgumentException

protected resetSystem()

Resets some other systems like rebuilding the route information or caches.

protected themeRegistryRebuild()

Wraps drupal_theme_rebuild().