function ConfigImportSubscriber::validateThemes
Same name in other branches
- 8.9.x core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php \Drupal\Core\EventSubscriber\ConfigImportSubscriber::validateThemes()
- 10 core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php \Drupal\Core\EventSubscriber\ConfigImportSubscriber::validateThemes()
- 11.x core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php \Drupal\Core\EventSubscriber\ConfigImportSubscriber::validateThemes()
Validates theme installations and uninstallations.
Parameters
\Drupal\Core\Config\ConfigImporter $config_importer: The configuration importer.
1 call to ConfigImportSubscriber::validateThemes()
- ConfigImportSubscriber::onConfigImporterValidate in core/
lib/ Drupal/ Core/ EventSubscriber/ ConfigImportSubscriber.php - Validates the configuration to be imported.
File
-
core/
lib/ Drupal/ Core/ EventSubscriber/ ConfigImportSubscriber.php, line 197
Class
- ConfigImportSubscriber
- Config import subscriber for config import events.
Namespace
Drupal\Core\EventSubscriberCode
protected function validateThemes(ConfigImporter $config_importer) {
$core_extension = $config_importer->getStorageComparer()
->getSourceStorage()
->read('core.extension');
// Get all themes including those that are not installed.
$theme_data = $this->getThemeData();
$module_data = $this->moduleExtensionList
->getList();
$nonexistent_themes = array_keys(array_diff_key($core_extension['theme'], $theme_data));
foreach ($nonexistent_themes as $theme) {
$config_importer->logError($this->t('Unable to install the %theme theme since it does not exist.', [
'%theme' => $theme,
]));
}
// Ensure that all themes being installed have their dependencies met.
$installs = $config_importer->getExtensionChangelist('theme', 'install');
foreach ($installs as $theme) {
$module_dependencies = $theme_data[$theme]->module_dependencies;
// $theme_data[$theme]->requires contains both theme and module
// dependencies keyed by the extension machine names.
// $theme_data[$theme]->module_dependencies contains only the module
// dependencies keyed by the module extension machine name. Therefore, we
// can find the theme dependencies by finding array keys for 'requires'
// that are not in $module_dependencies.
$theme_dependencies = array_diff_key($theme_data[$theme]->requires, $module_dependencies);
foreach (array_keys($theme_dependencies) as $required_theme) {
if (!isset($core_extension['theme'][$required_theme])) {
$theme_name = $theme_data[$theme]->info['name'];
$required_theme_name = $theme_data[$required_theme]->info['name'];
$config_importer->logError($this->t('Unable to install the %theme theme since it requires the %required_theme theme.', [
'%theme' => $theme_name,
'%required_theme' => $required_theme_name,
]));
}
}
foreach (array_keys($module_dependencies) as $required_module) {
if (!isset($core_extension['module'][$required_module])) {
$theme_name = $theme_data[$theme]->info['name'];
$required_module_name = $module_data[$required_module]->info['name'];
$config_importer->logError($this->t('Unable to install the %theme theme since it requires the %required_module module.', [
'%theme' => $theme_name,
'%required_module' => $required_module_name,
]));
}
}
}
// Ensure that all themes being uninstalled are not required by themes that
// will be installed after the import.
$uninstalls = $config_importer->getExtensionChangelist('theme', 'uninstall');
foreach ($uninstalls as $theme) {
foreach (array_keys($theme_data[$theme]->required_by) as $dependent_theme) {
if ($theme_data[$dependent_theme]->status && !in_array($dependent_theme, $uninstalls, TRUE)) {
$theme_name = $theme_data[$theme]->info['name'];
$dependent_theme_name = $theme_data[$dependent_theme]->info['name'];
$config_importer->logError($this->t('Unable to uninstall the %theme theme since the %dependent_theme theme is installed.', [
'%theme' => $theme_name,
'%dependent_theme' => $dependent_theme_name,
]));
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.