3 namespace Drupal\Core\Config\Entity;
5 use Drupal\Component\Utility\NestedArray;
8 * Provides a value object to discover configuration dependencies.
10 * @see \Drupal\Core\Config\Entity\ConfigDependencyManager
12 class ConfigEntityDependency {
15 * The configuration entity's configuration object name.
22 * The configuration entity's dependencies.
26 protected $dependencies = [];
29 * Constructs the configuration entity dependency from the entity values.
32 * The configuration entity's configuration object name.
33 * @param array $values
34 * (optional) The configuration entity's values.
36 public function __construct($name, $values = []) {
38 if (isset($values['dependencies']) && isset($values['dependencies']['enforced'])) {
39 // Merge the enforced dependencies into the list of dependencies.
40 $enforced_dependencies = $values['dependencies']['enforced'];
41 unset($values['dependencies']['enforced']);
42 $this->dependencies = NestedArray::mergeDeep($values['dependencies'], $enforced_dependencies);
44 elseif (isset($values['dependencies'])) {
45 $this->dependencies = $values['dependencies'];
50 * Gets the configuration entity's dependencies of the supplied type.
53 * The type of dependency to return. Either 'module', 'theme', 'config' or
57 * The list of dependencies of the supplied type.
59 public function getDependencies($type) {
61 if (isset($this->dependencies[$type])) {
62 $dependencies = $this->dependencies[$type];
64 if ($type == 'module') {
65 $dependencies[] = substr($this->name, 0, strpos($this->name, '.'));
71 * Determines if the entity is dependent on extensions or entities.
74 * The type of dependency being checked. Either 'module', 'theme', 'config'
77 * The specific name to check. If $type equals 'module' or 'theme' then it
78 * should be a module name or theme name. In the case of entity it should be
79 * the full configuration object name.
83 public function hasDependency($type, $name) {
84 // A config entity is always dependent on its provider.
85 if ($type == 'module' && strpos($this->name, $name . '.') === 0) {
88 return isset($this->dependencies[$type]) && array_search($name, $this->dependencies[$type]) !== FALSE;
92 * Gets the configuration entity's configuration dependency name.
94 * @see \Drupal\Core\Entity\EntityInterface::getConfigDependencyName()
97 * The configuration dependency name for the entity.
99 public function getConfigDependencyName() {