You are here

class ConfigListerWithProviders in Configuration Update Manager 8

Provides methods related to config listing, including provider calculation.

Hierarchy

Expanded class hierarchy of ConfigListerWithProviders

1 file declares its use of ConfigListerWithProviders
ConfigUpdateUiCliService.php in config_update_ui/src/ConfigUpdateUiCliService.php
1 string reference to 'ConfigListerWithProviders'
config_update.services.yml in ./config_update.services.yml
config_update.services.yml
1 service uses ConfigListerWithProviders
config_update.config_list in ./config_update.services.yml
Drupal\config_update\ConfigListerWithProviders

File

src/ConfigListerWithProviders.php, line 14

Namespace

Drupal\config_update
View source
class ConfigListerWithProviders extends ConfigLister implements ConfigListByProviderInterface {

  /**
   * List of providers of config, keyed by config item name.
   *
   * The array elements are each arrays, with the type of extension providing
   * the config object as the first element (module, theme, profile), and the
   * name of the provider as the second element.
   *
   * This is not set up until ConfigListerWithProviders::listProviders() has
   * been called.
   *
   * @var array
   */
  protected $providers = [];

  /**
   * List of extensions that provide configuration, keyed by type.
   *
   * This is not set up until ConfigListerWithProviders::listProviders() has
   * been called.
   *
   * @var array
   */
  protected $extensionsWithConfig = [];

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The theme handler.
   *
   * @var \Drupal\Core\Extension\ThemeHandlerInterface
   */
  protected $themeHandler;

  /**
   * Constructs a ConfigListerWithProviders.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity manager.
   * @param \Drupal\Core\Config\StorageInterface $active_config_storage
   *   The active config storage.
   * @param \Drupal\Core\Config\ExtensionInstallStorage $extension_config_storage
   *   The extension config storage.
   * @param \Drupal\Core\Config\ExtensionInstallStorage $extension_optional_config_storage
   *   The extension config storage for optional config items.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
   *   The theme handler.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager, StorageInterface $active_config_storage, ExtensionInstallStorage $extension_config_storage, ExtensionInstallStorage $extension_optional_config_storage, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
    $this->entityManager = $entity_manager;
    $this->activeConfigStorage = $active_config_storage;
    $this->extensionConfigStorage = $extension_config_storage;
    $this->extensionOptionalConfigStorage = $extension_optional_config_storage;
    $this->moduleHandler = $module_handler;
    $this->themeHandler = $theme_handler;
  }

  /**
   * Sets up and returns the config providers list.
   */
  public function listProviders() {

    // Return the list if it has already been set up.
    if (count($this->providers)) {
      return $this->providers;
    }

    // Calculate the list of who provides which config, if it hasn't been set
    // up yet. List all of the profile, modules, and themes. Profile needs to
    // come last, so it will override config in modules and themes in our list,
    // matching what the config system does.
    $extensionsToDo = [];
    $profile = $this
      ->getProfileName();
    $modules = $this->moduleHandler
      ->getModuleList();
    foreach ($modules as $machine_name => $module) {
      if ($machine_name != $profile) {
        $extensionsToDo[] = [
          'module',
          $machine_name,
        ];
      }
    }
    $themes = $this->themeHandler
      ->listInfo();
    foreach ($themes as $machine_name => $theme) {
      $extensionsToDo[] = [
        'theme',
        $machine_name,
      ];
    }
    $extensionsToDo[] = [
      'profile',
      $profile,
    ];

    // For each extension, figure out if it has config, and make an index of
    // config item => provider.
    $this->extensionsWithConfig = [
      'profile' => [],
      'module' => [],
      'theme' => [],
    ];
    foreach ($extensionsToDo as $item) {
      $type = $item[0];
      $name = $item[1];
      $configs = array_merge($this
        ->listProvidedItems($type, $name), $this
        ->listProvidedItems($type, $name, TRUE));
      if (!empty($configs)) {
        $this->extensionsWithConfig[$type][$name] = $name;
        foreach ($configs as $config) {
          $this->providers[$config] = [
            $type,
            $name,
          ];
        }
      }
    }
    return $this->providers;
  }

  /**
   * {@inheritdoc}
   */
  public function getConfigProvider($name) {
    $providers = $this
      ->listProviders();
    return isset($providers[$name]) ? $providers[$name] : NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function providerHasConfig($type, $name) {

    // Make sure the list of extensions with configuration has been generated.
    $this
      ->listProviders();
    return isset($this->extensionsWithConfig[$type][$name]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigLister::$activeConfigStorage protected property The active config storage.
ConfigLister::$definitions protected property List of current config entity type definitions, keyed by entity type.
ConfigLister::$entityManager protected property The entity manager.
ConfigLister::$extensionConfigStorage protected property The extension config storage.
ConfigLister::$extensionOptionalConfigStorage protected property The extension config storage for optional config.
ConfigLister::$typesByPrefix protected property List of current config entity types, keyed by prefix.
ConfigLister::getProfileName protected function Returns the name of the install profile.
ConfigLister::getType public function Returns the entity type object for a given config type name. Overrides ConfigListInterface::getType
ConfigLister::getTypeByPrefix public function Returns the entity type object for a given config prefix. Overrides ConfigListInterface::getTypeByPrefix
ConfigLister::getTypeNameByConfigName public function Returns the config type name for a given config object. Overrides ConfigListInterface::getTypeNameByConfigName
ConfigLister::listConfig public function Lists the config objects in active and extension storage. Overrides ConfigListInterface::listConfig
ConfigLister::listProvidedItems protected function Returns a list of the install storage items for an extension.
ConfigLister::listTypes public function Sets up and returns the entity definitions list. Overrides ConfigListInterface::listTypes
ConfigLister::omitKnownPrefixes protected function Omits config with known prefixes from a list of config names.
ConfigListerWithProviders::$extensionsWithConfig protected property List of extensions that provide configuration, keyed by type.
ConfigListerWithProviders::$moduleHandler protected property The module handler.
ConfigListerWithProviders::$providers protected property List of providers of config, keyed by config item name.
ConfigListerWithProviders::$themeHandler protected property The theme handler.
ConfigListerWithProviders::getConfigProvider public function Returns the provider of a given config object. Overrides ConfigListByProviderInterface::getConfigProvider
ConfigListerWithProviders::listProviders public function Sets up and returns the config providers list.
ConfigListerWithProviders::providerHasConfig public function Lists the providers of a given type that actually have configuration. Overrides ConfigListByProviderInterface::providerHasConfig
ConfigListerWithProviders::__construct public function Constructs a ConfigListerWithProviders. Overrides ConfigLister::__construct