depcalc-8.x-1.x-dev/depcalc.module
depcalc.module
<?php
/**
* @file
* Drupal Module: Dependency Calculation.
*
* Calculates recursive dependencies of any entity.
*/
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
use Drupal\depcalc\DependencyCalculatorEvents;
use Drupal\depcalc\Event\InvalidateDepcalcCacheEvent;
use Drupal\Core\Site\Settings;
use Drupal\depcalc\DepcalcRequirements;
/**
* Implements hook_entity_presave().
*/
function depcalc_entity_presave(EntityInterface $entity) {
if ($entity->uuid()) {
$event = new InvalidateDepcalcCacheEvent($entity);
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher */
$event_dispatcher = \Drupal::service('event_dispatcher');
$event_dispatcher->dispatch($event, DependencyCalculatorEvents::INVALIDATE_DEPCALC_CACHE);
}
}
/**
* Implements hook_entity_delete().
*/
function depcalc_entity_delete(EntityInterface $entity) {
if ($uuid = $entity->uuid()) {
$backend = \Drupal::cache('depcalc');
$backend->delete($uuid);
Cache::invalidateTags([$uuid]);
}
}
/**
* Implements hook_requirements().
*/
function depcalc_requirements($phase) {
$requirements = [];
if ($phase == 'install' || $phase == 'runtime') {
$depcalc_requirements = new DepcalcRequirements(Settings::getInstance());
return $depcalc_requirements->getRequirements();
}
return $requirements;
}
