public function DependentEntityWrapper::addDependency in Dependency Calculation 8
Document a new dependency for this entity.
Parameters
\Drupal\depcalc\DependentEntityWrapperInterface $dependency: The dependency to add.
\Drupal\depcalc\DependencyStack $stack: The dependency stack.
bool $direct_child: Whether given wrapper is a direct child.
Overrides DependentEntityWrapperInterface::addDependency
1 call to DependentEntityWrapper::addDependency()
- DependentEntityWrapper::addDependencies in src/
DependentEntityWrapper.php - Add dependencies of this entity.
File
- src/
DependentEntityWrapper.php, line 151
Class
- DependentEntityWrapper
- An entity wrapper class for finding and tracking dependencies of an entity.
Namespace
Drupal\depcalcCode
public function addDependency(DependentEntityWrapperInterface $dependency, DependencyStack $stack, bool $direct_child = TRUE) {
// Don't save a thing as a dependency of itself.
if ($dependency
->getUuid() === $this
->getUUid()) {
return;
}
if (!array_key_exists($dependency
->getUuid(), $this->dependencies)) {
$this->dependencies[$dependency
->getUuid()] = $dependency
->getHash();
// Add this dependency to direct child dependency array.
if ($direct_child && !array_key_exists($dependency
->getUuid(), $this->childDependencies)) {
// Minimal data needed to load this child entity.
$this->childDependencies[$dependency
->getUuid()] = $dependency
->getUuid();
}
if (!$stack
->hasDependency($dependency
->getUuid())) {
$stack
->addDependency($dependency);
foreach ($stack
->getDependenciesByUuid(array_keys($dependency
->getDependencies())) as $sub_dependency) {
// Since these are sub-dependencies, so setting the boolean to false.
$this
->addDependency($sub_dependency, $stack, FALSE);
}
}
else {
$this
->addDependencies($stack, ...array_values($stack
->getDependenciesByUuid(array_keys($stack
->getDependency($dependency
->getUuid())
->getDependencies()))));
}
$modules = $stack
->getDependency($dependency
->getUuid())
->getModuleDependencies();
if ($modules) {
$this
->addModuleDependencies($modules);
}
}
}