Loading src/Commands/NodeRevisionDeleteCommands.php +69 −14 Changes for src/Commands/NodeRevisionDeleteCommands.php: 69 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -380,7 +380,7 @@ class NodeRevisionDeleteCommands extends DrushCommands { } /** * Validate inputs before executing the drush command. * Validate inputs before executing the drush command node-revision-delete. * * @param \Consolidation\AnnotatedCommand\CommandData $commandData * The command data. Loading @@ -394,18 +394,7 @@ class NodeRevisionDeleteCommands extends DrushCommands { $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, ] )); if (!$this->configuredContentType($type)) { return FALSE; } Loading @@ -419,7 +408,7 @@ class NodeRevisionDeleteCommands extends DrushCommands { } /** * Validate inputs before executing the drush command. * Validate inputs before executing the drush command nrd-dpr. * * @param \Consolidation\AnnotatedCommand\CommandData $commandData * The command data. Loading Loading @@ -459,4 +448,70 @@ class NodeRevisionDeleteCommands extends DrushCommands { return TRUE; } /** * Untrack a content type. * * @param string $type * The content type name. * * @usage nrd-untrack article * Untrack the content type article. * @command nrd:untrack * @aliases nrd-u, nrd-untrack */ public function untrack(string $type): void { $this->nodeRevisionDelete->deleteContentTypeConfig($type); $message = dt('<info>The content type @type is now untracked.</info>', ['@type' => $type]); $this->writeln($message); } /** * Validate inputs before executing the drush command nrd-untrack. * * @param \Consolidation\AnnotatedCommand\CommandData $commandData * The command data. * * @return bool * Returns TRUE if the validations has passed FALSE otherwise. * * @hook validate nrd-u */ public function untrackValidate(CommandData $commandData): bool { $input = $commandData->input(); $type = $input->getArgument('type'); if (!$this->configuredContentType($type)) { return FALSE; } return TRUE; } /** * Validate inputs before executing the drush command nrd-untrack. * * @param string $type * The content type name. * * @return bool * Returns if a content type is configured. */ private function configuredContentType(string $type): bool { // Make sure the content type exists and is configured. $available_content_types = array_map(static function ($content_type) { /** @var \Drupal\node\NodeTypeInterface $content_type */ return $content_type->id(); }, $this->nodeRevisionDelete->getConfiguredContentTypes()); if (!in_array($type, $available_content_types, TRUE)) { $this->io()->error(dt('The following content type is not configured for revision deletion: @name', [ '@name' => $type, ] )); return FALSE; } return TRUE; } } Loading
src/Commands/NodeRevisionDeleteCommands.php +69 −14 Changes for src/Commands/NodeRevisionDeleteCommands.php: 69 added lines, 14 removed lines. Original line number Diff line number Diff line Loading @@ -380,7 +380,7 @@ class NodeRevisionDeleteCommands extends DrushCommands { } /** * Validate inputs before executing the drush command. * Validate inputs before executing the drush command node-revision-delete. * * @param \Consolidation\AnnotatedCommand\CommandData $commandData * The command data. Loading @@ -394,18 +394,7 @@ class NodeRevisionDeleteCommands extends DrushCommands { $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, ] )); if (!$this->configuredContentType($type)) { return FALSE; } Loading @@ -419,7 +408,7 @@ class NodeRevisionDeleteCommands extends DrushCommands { } /** * Validate inputs before executing the drush command. * Validate inputs before executing the drush command nrd-dpr. * * @param \Consolidation\AnnotatedCommand\CommandData $commandData * The command data. Loading Loading @@ -459,4 +448,70 @@ class NodeRevisionDeleteCommands extends DrushCommands { return TRUE; } /** * Untrack a content type. * * @param string $type * The content type name. * * @usage nrd-untrack article * Untrack the content type article. * @command nrd:untrack * @aliases nrd-u, nrd-untrack */ public function untrack(string $type): void { $this->nodeRevisionDelete->deleteContentTypeConfig($type); $message = dt('<info>The content type @type is now untracked.</info>', ['@type' => $type]); $this->writeln($message); } /** * Validate inputs before executing the drush command nrd-untrack. * * @param \Consolidation\AnnotatedCommand\CommandData $commandData * The command data. * * @return bool * Returns TRUE if the validations has passed FALSE otherwise. * * @hook validate nrd-u */ public function untrackValidate(CommandData $commandData): bool { $input = $commandData->input(); $type = $input->getArgument('type'); if (!$this->configuredContentType($type)) { return FALSE; } return TRUE; } /** * Validate inputs before executing the drush command nrd-untrack. * * @param string $type * The content type name. * * @return bool * Returns if a content type is configured. */ private function configuredContentType(string $type): bool { // Make sure the content type exists and is configured. $available_content_types = array_map(static function ($content_type) { /** @var \Drupal\node\NodeTypeInterface $content_type */ return $content_type->id(); }, $this->nodeRevisionDelete->getConfiguredContentTypes()); if (!in_array($type, $available_content_types, TRUE)) { $this->io()->error(dt('The following content type is not configured for revision deletion: @name', [ '@name' => $type, ] )); return FALSE; } return TRUE; } }