commit 2ff10d1216f4831d393d1f5be709909ced297b5a
Author: Moshe Weitzman <weitzman@tejasa.com>
Date:   Thu Nov 7 09:47:38 2019 -0500

    Add Drush command for Purger

diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..43d913a
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,12 @@
+{
+    "name": "drupal/entity_reference_revisions",
+    "description": "Adds a Entity Reference field type with revision support.",
+    "type": "drupal-module",
+    "extra": {
+        "drush": {
+            "services": {
+                "drush.services.yml": "^9 || ^10"
+            }
+        }
+    }
+}
diff --git a/drush.services.yml b/drush.services.yml
new file mode 100644
index 0000000..fad7549
--- /dev/null
+++ b/drush.services.yml
@@ -0,0 +1,6 @@
+services:
+  entity_reference_revisions.commands:
+    class: \Drupal\entity_reference_revisions\Commands\EntityReferenceRevisionsCommands
+    arguments: ['@entity_reference_revisions.orphan_purger']
+    tags:
+      - { name: drush.command }
diff --git a/src/Commands/EntityReferenceRevisionsCommands.php b/src/Commands/EntityReferenceRevisionsCommands.php
new file mode 100644
index 0000000..d23d307
--- /dev/null
+++ b/src/Commands/EntityReferenceRevisionsCommands.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Drupal\entity_reference_revisions\Commands;
+
+use Drupal\entity_reference_revisions\EntityReferenceRevisionsOrphanPurger;
+use Drush\Commands\DrushCommands;
+use Drush\Drush;
+use Drush\Utils\StringUtils;
+
+/**
+ * A Drush commandfile.
+ */
+class EntityReferenceRevisionsCommands extends DrushCommands {
+
+  /**
+   * The purger service.
+   *
+   * @var \Drupal\entity_reference_revisions\EntityReferenceRevisionsOrphanPurger
+   */
+  protected $purger;
+
+  /**
+   * Constructs a ERRCommands object.
+   *
+   * @param \Drupal\entity_reference_revisions\EntityReferenceRevisionsOrphanPurger $purger
+   */
+  public function __construct(EntityReferenceRevisionsOrphanPurger $purger) {
+    $this->purger = $purger;
+  }
+
+  /**
+   * Orphan composite revision deletion.
+   *
+   * @param $types
+   *   A comma delimited list of entity types to check for orphans. Omit to
+   *   choose from a list.
+   * @usage drush err:purge paragraph
+   *   Purge orphaned paragraphs.
+   *
+   * @command err:purge
+   * @aliases errp
+   */
+  public function purge($types) {
+    $this->purger->setBatch(StringUtils::csvToArray($types));
+    drush_backend_batch_process();
+  }
+
+  /**
+   * @hook interact err:purge
+   */
+  public function interact($input, $output) {
+    if (empty($input->getArgument('types'))) {
+      $choices = [];
+      foreach ($this->purger->getCompositeEntityTypes() as $entity_type) {
+        $choices[(string) $entity_type->id()] = (string) $entity_type->getLabel();
+      }
+      $selected = $this->io()->choice(dt("Choose the entity type to clear"), $choices);
+      $input->setArgument('types', $selected);
+    }
+  }
+
+}
diff --git a/src/EntityReferenceRevisionsOrphanPurger.php b/src/EntityReferenceRevisionsOrphanPurger.php
index 8735817..ef58e27 100644
--- a/src/EntityReferenceRevisionsOrphanPurger.php
+++ b/src/EntityReferenceRevisionsOrphanPurger.php
@@ -138,10 +138,10 @@ class EntityReferenceRevisionsOrphanPurger {
    *
    * @param string $entity_type_id
    *   The entity type id, for example 'paragraph'.
-   * @param array $context
+   * @param $context
    *   The context array.
    */
-  public function deleteOrphansBatchOperation($entity_type_id, array &$context) {
+  public function deleteOrphansBatchOperation($entity_type_id, &$context) {
     $composite_type = $this->entityTypeManager->getDefinition($entity_type_id);
     $composite_revision_key = $composite_type->getKey('revision');
     /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $composite_storage */
@@ -367,4 +367,24 @@ class EntityReferenceRevisionsOrphanPurger {
     return $status;
   }
 
+  /**
+   * Returns a list of composite entity types.
+   *
+   * @return \Drupal\Core\Entity\EntityTypeInterface[]
+   *   An array of composite entity types.
+   */
+  public function getCompositeEntityTypes() {
+    $composite_entity_types = [];
+    $entity_types = $this->entityTypeManager->getDefinitions();
+    foreach ($entity_types as $entity_type) {
+      $has_parent_type_field = $entity_type->get('entity_revision_parent_type_field');
+      $has_parent_id_field = $entity_type->get('entity_revision_parent_id_field');
+      $has_parent_field_name_field = $entity_type->get('entity_revision_parent_field_name_field');
+      if ($has_parent_type_field && $has_parent_id_field && $has_parent_field_name_field) {
+        $composite_entity_types[] = $entity_type;
+      }
+    }
+    return $composite_entity_types;
+  }
+
 }
diff --git a/src/Form/OrphanedCompositeEntitiesDeleteForm.php b/src/Form/OrphanedCompositeEntitiesDeleteForm.php
index b3da36d..6267c97 100644
--- a/src/Form/OrphanedCompositeEntitiesDeleteForm.php
+++ b/src/Form/OrphanedCompositeEntitiesDeleteForm.php
@@ -80,7 +80,7 @@ class OrphanedCompositeEntitiesDeleteForm extends FormBase {
       '#markup' => $this->t('Delete orphaned composite entities revisions that are no longer referenced. If there are no revisions left, the entity will be deleted as long as it is not used.'),
     ];
     $options = [];
-    foreach ($this->getCompositeEntityTypes() as $entity_type) {
+    foreach ($this->purger->getCompositeEntityTypes() as $entity_type) {
       $options[$entity_type->id()] = $entity_type->getLabel();
     }
     $form['composite_entity_types'] = [
@@ -107,24 +107,4 @@ class OrphanedCompositeEntitiesDeleteForm extends FormBase {
     $this->purger->setBatch(array_filter($form_state->getValue('composite_entity_types')));
   }
 
-  /**
-   * Returns a list of composite entity types.
-   *
-   * @return \Drupal\Core\Entity\EntityTypeInterface[]
-   *   An array of composite entity types.
-   */
-  public function getCompositeEntityTypes() {
-    $composite_entity_types = [];
-    $entity_types = $this->entityTypeManager->getDefinitions();
-    foreach ($entity_types as $entity_type) {
-      $has_parent_type_field = $entity_type->get('entity_revision_parent_type_field');
-      $has_parent_id_field = $entity_type->get('entity_revision_parent_id_field');
-      $has_parent_field_name_field = $entity_type->get('entity_revision_parent_field_name_field');
-      if ($has_parent_type_field && $has_parent_id_field && $has_parent_field_name_field) {
-        $composite_entity_types[] = $entity_type;
-      }
-    }
-    return $composite_entity_types;
-  }
-
 }
