You are here

protected function ConfigProviderBase::validateDependencies in Configuration Provider 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/ConfigProviderBase.php \Drupal\config_provider\Plugin\ConfigProviderBase::validateDependencies()

Validates an array of config data that contains dependency information.

Parameters

string $config_name: The name of the configuration object that is being validated.

array $data: Configuration data.

array $enabled_extensions: A list of all the currently enabled modules and themes.

array $all_config: A list of all the active configuration names.

Return value

bool TRUE if the dependencies are met, FALSE if not.

1 call to ConfigProviderBase::validateDependencies()
ConfigProviderOptional::addInstallableConfig in src/Plugin/ConfigProvider/ConfigProviderOptional.php
Adds configuration that is available to be installed or updated.

File

src/Plugin/ConfigProviderBase.php, line 137

Class

ConfigProviderBase
Base class for Configuration provider plugins.

Namespace

Drupal\config_provider\Plugin

Code

protected function validateDependencies($config_name, array $data, array $enabled_extensions, array $all_config) {
  if (isset($data['dependencies'])) {
    $all_dependencies = $data['dependencies'];

    // Ensure enforced dependencies are included.
    if (isset($all_dependencies['enforced'])) {
      $all_dependencies = array_merge($all_dependencies, $data['dependencies']['enforced']);
      unset($all_dependencies['enforced']);
    }

    // Ensure the configuration entity type provider is in the list of
    // dependencies.
    list($provider) = explode('.', $config_name, 2);
    if (!isset($all_dependencies['module'])) {
      $all_dependencies['module'][] = $provider;
    }
    elseif (!in_array($provider, $all_dependencies['module'])) {
      $all_dependencies['module'][] = $provider;
    }
    foreach ($all_dependencies as $type => $dependencies) {
      $list_to_check = [];
      switch ($type) {
        case 'module':
        case 'theme':
          $list_to_check = $enabled_extensions;
          break;
        case 'config':
          $list_to_check = $all_config;
          break;
      }
      if (!empty($list_to_check)) {
        $missing = array_diff($dependencies, $list_to_check);
        if (!empty($missing)) {
          return FALSE;
        }
      }
    }
  }
  return TRUE;
}