function NodeHooks1::userPredelete

Implements hook_ENTITY_TYPE_predelete() for user entities.

File

core/modules/node/src/Hook/NodeHooks1.php, line 250

Class

NodeHooks1
Hook implementations for node.

Namespace

Drupal\node\Hook

Code

public function userPredelete($account) {
    // Delete nodes (current revisions).
    // @todo Introduce node_mass_delete() or make node_mass_update() more flexible.
    $nids = \Drupal::entityQuery('node')->condition('uid', $account->id())
        ->accessCheck(FALSE)
        ->execute();
    // Delete old revisions.
    $storage_controller = \Drupal::entityTypeManager()->getStorage('node');
    $nodes = $storage_controller->loadMultiple($nids);
    $storage_controller->delete($nodes);
    $revisions = $storage_controller->userRevisionIds($account);
    foreach ($revisions as $revision) {
        $storage_controller->deleteRevision($revision);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.