You are here

public function ServiceResource::calculateDependencies in Services 9.0.x

Same name and namespace in other branches
  1. 8.4 src/Entity/ServiceResource.php \Drupal\services\Entity\ServiceResource::calculateDependencies()

Calculates dependencies and stores them in the dependency property.

Return value

$this

Overrides ConfigEntityBase::calculateDependencies

See also

\Drupal\Core\Config\Entity\ConfigDependencyManager

File

src/Entity/ServiceResource.php, line 215

Class

ServiceResource
Defines service resource entity.

Namespace

Drupal\services\Entity

Code

public function calculateDependencies() {
  parent::calculateDependencies();

  // Calculate the dependencies based on the selected authentications that
  // have been selected for a given services resource.
  if ($this instanceof ServiceResourceInterface) {
    foreach ($this
      ->getAuthentication() as $provider_id) {
      $provider = $this
        ->authenticationCollector()
        ->getProvider($provider_id);
      if (!$provider instanceof AuthenticationProviderInterface) {
        continue;
      }
      $class_info = explode('\\', get_class($provider));
      $module_name = $class_info[1];

      // Make sure the module exists prior to requiring it as a dependency.
      if (\Drupal::moduleHandler()
        ->moduleExists($module_name)) {
        $this
          ->addDependency('module', $module_name);
      }
    }
  }
  return $this;
}