class NodeHooks

Hook implementations for the node module.

Hierarchy

Expanded class hierarchy of NodeHooks

File

core/modules/node/src/Hook/NodeHooks.php, line 16

Namespace

Drupal\node\Hook
View source
class NodeHooks {
  
  /**
   * The Node Storage.
   *
   * @var \Drupal\node\NodeStorageInterface
   */
  protected NodeStorageInterface $nodeStorage;
  
  /**
   * NodeHooks constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   The entity type manager.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
   *   The module handler.
   */
  public function __construct(EntityTypeManagerInterface $entityTypeManager, protected ModuleHandlerInterface $moduleHandler) {
    $this->nodeStorage = $entityTypeManager->getStorage('node');
  }
  
  /**
   * Implements hook_user_cancel().
   *
   * Unpublish nodes (current revisions).
   */
  public function userCancelBlockUnpublish($edit, UserInterface $account, $method) : void {
    if ($method === 'user_cancel_block_unpublish') {
      $nids = $this->nodeStorage
        ->getQuery()
        ->accessCheck(FALSE)
        ->condition('uid', $account->id())
        ->execute();
      $this->moduleHandler
        ->invoke('node', 'mass_update', [
        $nids,
        [
          'status' => 0,
        ],
        NULL,
        TRUE,
      ]);
    }
  }
  
  /**
   * Implements hook_user_cancel().
   *
   * Anonymize all of the nodes for this old account.
   */
  public function userCancelReassign($edit, UserInterface $account, $method) : void {
    if ($method === 'user_cancel_reassign') {
      $vids = $this->nodeStorage
        ->userRevisionIds($account);
      $this->moduleHandler
        ->invoke('node', 'mass_update', [
        $vids,
        [
          'uid' => 0,
          'revision_uid' => 0,
        ],
        NULL,
        TRUE,
        TRUE,
      ]);
    }
  }
  
  /**
   * Implements hook_block_alter().
   */
  public function blockAlter(&$definitions) : void {
    // Hide the deprecated Syndicate block from the UI.
    $definitions['node_syndicate_block']['_block_ui_hidden'] = TRUE;
  }

}

Members

Title Sort descending Modifiers Object type Summary
NodeHooks::$nodeStorage protected property The Node Storage.
NodeHooks::blockAlter public function Implements hook_block_alter().
NodeHooks::userCancelBlockUnpublish public function Implements hook_user_cancel().
NodeHooks::userCancelReassign public function Implements hook_user_cancel().
NodeHooks::__construct public function NodeHooks constructor.

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