You are here

function workbench_access_entity_delete in Workbench Access 8

Implements hook_entity_delete().

File

./workbench_access.module, line 72
Contains workbench_access.module.

Code

function workbench_access_entity_delete(EntityInterface $entity) {
  foreach (\Drupal::entityTypeManager()
    ->getStorage('access_scheme')
    ->loadMultiple() as $scheme) {
    $entity_type = $scheme
      ->getAccessScheme()
      ->entityType();
    if ($entity_type === $entity
      ->getEntityTypeId()) {

      // Delete all associated storage.
      $section_storage = \Drupal::entityTypeManager()
        ->getStorage('section_association');
      $sections = $section_storage
        ->loadByProperties([
        'access_scheme' => $scheme
          ->id(),
        'section_id' => $entity
          ->id(),
      ]);
      $section_storage
        ->delete($sections);
      \Drupal::service('workbench_access.user_section_storage')
        ->resetCache($scheme);
    }
  }
}