You are here

public function NodeRevisionDeleteCommands::deletePriorRevisionsValidate in Node Revision Delete 8

Validate inputs before executing the drush command.

@hook validate nrd-delete-prior-revisions

Parameters

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

Return value

bool Returns TRUE if the validations has passed FALSE otherwise.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/Commands/NodeRevisionDeleteCommands.php, line 433

Class

NodeRevisionDeleteCommands
Class NodeRevisionDeleteCommands.

Namespace

Drupal\node_revision_delete\Commands

Code

public function deletePriorRevisionsValidate(CommandData $commandData) {
  $input = $commandData
    ->input();
  $nid = $input
    ->getArgument('nid');
  $vid = $input
    ->getArgument('vid');

  // Nid argument must be numeric.
  if (!is_numeric($nid)) {
    $this
      ->io()
      ->error(dt('Argument nid must be numeric.'));
    return FALSE;
  }

  // Vid argument must be numeric.
  if (!is_numeric($vid)) {
    $this
      ->io()
      ->error(dt('Argument vid must be numeric.'));
    return FALSE;
  }

  // Check if argument nid is a valid node id.
  $node = $this->entityTypeManager
    ->getStorage('node')
    ->load($nid);
  if (is_null($node)) {
    $this
      ->io()
      ->error(dt("@nid is not a valid node id.", [
      '@nid' => $nid,
    ]));
    return FALSE;
  }
  return TRUE;
}