Change record status: 
Introduced in branch: 
2.1.x
Introduced in version: 
2.1.0
Description: 

\Drupal\node_revision_delete\Plugin\NodeRevisionDeleteInterface::checkRevisions() is deprecated and will be removed in node_revision_delete 3.0.0. All plugins must implement \Drupal\node_revision_delete\Plugin\NodeRevisionDeleteQueryInterface instead. This new interface replaces the revision-loading approach with entity queries, significantly improving performance for nodes with many revisions.

How does this affect my module?

If your module provides a custom NodeRevisionDelete plugin that only implements NodeRevisionDeleteInterface, it will continue to work but will trigger a deprecation notice. You must update your plugin to also implement NodeRevisionDeleteQueryInterface before node_revision_delete 3.0.0.

What changed?

Previously, the queue worker loaded every revision entity individually and passed a flat array of revision IDs to each plugin's checkRevisions() method. Plugins returned TRUE (delete), FALSE (protect), or NULL (no opinion) for each revision.

The new NodeRevisionDeleteQueryInterface replaces this with two methods that receive a pre-configured entity revision query. Plugins add their own conditions to the query and return it, allowing the queue worker to determine which revisions to delete or protect without loading every revision entity.

The base query passed to each method already has these conditions applied:

  • nid = the node being processed
  • langcode = the language being evaluated
  • revision_translation_affected = 1
  • accessCheck(FALSE)

Example code

Before (deprecated)

  use Drupal\node_revision_delete\Plugin\NodeRevisionDeleteBase;

  class MyPlugin extends NodeRevisionDeleteBase {

    public function checkRevisions(array $revision_ids, int $active_vid): array {
      $revision_statuses = [];
      foreach ($revision_ids as $vid) {
        $revision_statuses[$vid] = NULL;
        $revision = $this->entityTypeManager->getStorage('node')->loadRevision($vid);
        if ($vid < $active_vid && $revision->my_field->value === 'my_value') {
          $revision_statuses[$vid] = TRUE;
        }
        elseif ($vid < $active_vid && $revision->my_field->value !== 'my_value') {
          $revision_statuses[$vid] = FALSE;
        }
      }
      return $revision_statuses;
    }

  }

After

  use Drupal\Core\Entity\Query\QueryInterface;
  use Drupal\node_revision_delete\Plugin\NodeRevisionDeleteBase;
  use Drupal\node_revision_delete\Plugin\NodeRevisionDeleteQueryInterface;

  class MyPlugin extends NodeRevisionDeleteBase implements NodeRevisionDeleteQueryInterface {

    public function getRevisionsToDelete(QueryInterface $query, int $active_vid): QueryInterface {
      return $query
        ->condition('vid', $active_vid, '<')
        ->condition('my_field', 'my_value');
    }

    public function getRevisionsToProtect(QueryInterface $query, int $active_vid): QueryInterface {
      return $query
        ->condition('vid', $active_vid, '<')
        ->condition('my_field', 'my_value', '<>');
    }

    /**
     * {@inheritdoc}
     *
     * @deprecated in node_revision_delete:2.1.0 and is removed from
     *   node_revision_delete:3.0.0. Use getRevisionsToDelete() and
     *   getRevisionsToProtect() instead.
     *
     * @see https://www.drupal.org/node/3581259
     */
    public function checkRevisions(array $revision_ids, int $active_vid): array {
      @trigger_error(__METHOD__ . '() is deprecated in node_revision_delete:2.1.0 and is removed from node_revision_delete:3.0.0. Use getRevisionsToDelete() and getRevisionsToProtect() instead. See https://www.drupal.org/node/3581259',
  E_USER_DEPRECATED);
      // Keep old implementation for backwards compatibility.
    }

  }
Impacts: 
Module developers