You are here

public function NodeRevisionDeleteCommands::nodeRevisionDeleteValidate in Node Revision Delete 8

Validate inputs before executing the drush command.

@hook validate nrd

Parameters

\Consolidation\AnnotatedCommand\CommandData $commandData: The command data.

Return value

bool Returns TRUE if the validations has passed FALSE otherwise.

File

src/Commands/NodeRevisionDeleteCommands.php, line 391

Class

NodeRevisionDeleteCommands
Class NodeRevisionDeleteCommands.

Namespace

Drupal\node_revision_delete\Commands

Code

public function nodeRevisionDeleteValidate(CommandData $commandData) {
  $input = $commandData
    ->input();
  $type = $input
    ->getArgument('type');

  // Make sure the content type exists and is configured.
  $available_content_types = array_map(function ($content_type) {

    /** @var \Drupal\node\NodeTypeInterface $content_type */
    return $content_type
      ->id();
  }, $this->nodeRevisionDelete
    ->getConfiguredContentTypes());
  if (!in_array($type, $available_content_types)) {
    $this
      ->io()
      ->error(dt('The following content type is not configured for revision deletion: @name', [
      '@name' => $type,
    ]));
    return FALSE;
  }

  // Checking if we have candidates nodes to delete.
  $candidates = count($this->nodeRevisionDelete
    ->getCandidatesRevisions($type));
  if (!$candidates) {
    $this
      ->io()
      ->warning(dt('There are no revisions to delete for @content_type.', [
      '@content_type' => $type,
    ]));
  }
  return TRUE;
}