You are here

function filebrowser_node_delete in Filebrowser 3.x

Same name and namespace in other branches
  1. 8.2 filebrowser.module \filebrowser_node_delete()

Deletes an Metadata entity when its provider node gets deleted

Implements hook_entity_delete(). @inheritdoc

File

./filebrowser.module, line 214

Code

function filebrowser_node_delete(NodeInterface $node) {
  if ($node
    ->bundle() == 'dir_listing') {

    // get all the entities for this node
    $query = \Drupal::entityQuery('filebrowser_metadata_entity')
      ->condition('nid', $node
      ->id(), '=');
    $ids = $query
      ->execute();
    $storage = \Drupal::entityTypeManager()
      ->getStorage('filebrowser_metadata_entity');
    $entities = $storage
      ->loadMultiple($ids);
    if ($entities) {
      foreach ($entities as $entity) {
        $entity
          ->delete();
      }
    }
  }
}