W3cubDocs

/Drupal 8

protected function ConfigImportSubscriber::validateThemes

protected ConfigImportSubscriber::validateThemes(ConfigImporter $config_importer)

Validates theme installations and uninstallations.

Parameters

\Drupal\Core\Config\ConfigImporter $config_importer: The configuration importer.

File

core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php, line 144

Class

ConfigImportSubscriber
Config import subscriber for config import events.

Namespace

Drupal\Core\EventSubscriber

Code

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();
  $installs = $config_importer->getExtensionChangelist('theme', 'install');
  foreach ($installs as $key => $theme) {
    if (!isset($theme_data[$theme])) {
      $config_importer->logError($this->t('Unable to install the %theme theme since it does not exist.', array('%theme' => $theme)));
      // Remove non-existing installs from the list so we can validate theme
      // dependencies later.
      unset($installs[$key]);
    }
  }

  // Ensure that all themes being installed have their dependencies met.
  foreach ($installs as $theme) {
    foreach (array_keys($theme_data[$theme]->requires) 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.', array('%theme' => $theme_name, '%required_theme' => $required_theme_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.', array('%theme' => $theme_name, '%dependent_theme' => $dependent_theme_name)));
      }
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!EventSubscriber!ConfigImportSubscriber.php/function/ConfigImportSubscriber::validateThemes/8.1.x