5 * Contains \Drupal\Console\Command\Views\DisableCommand.
8 namespace Drupal\Console\Command\Views;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Core\Command\Shared\CommandTrait;
15 use Drupal\Core\Entity\EntityTypeManagerInterface;
16 use Drupal\Core\Entity\Query\QueryFactory;
17 use Drupal\Console\Core\Style\DrupalStyle;
20 * Class DisableCommand
22 * @package Drupal\Console\Command\Views
24 class DisableCommand extends Command
29 * @var EntityTypeManagerInterface
31 protected $entityTypeManager;
36 protected $entityQuery;
39 * DisableCommand constructor.
41 * @param EntityTypeManagerInterface $entityTypeManager
42 * @param QueryFactory $entityQuery
44 public function __construct(
45 EntityTypeManagerInterface $entityTypeManager,
46 QueryFactory $entityQuery
48 $this->entityTypeManager = $entityTypeManager;
49 $this->entityQuery = $entityQuery;
50 parent::__construct();
56 protected function configure()
59 ->setName('views:disable')
60 ->setDescription($this->trans('commands.views.disable.description'))
63 InputArgument::OPTIONAL,
64 $this->trans('commands.views.debug.arguments.view-id')
71 protected function interact(InputInterface $input, OutputInterface $output)
73 $io = new DrupalStyle($input, $output);
74 $viewId = $input->getArgument('view-id');
76 $views = $this->entityQuery
78 ->condition('status', 1)
80 $viewId = $io->choiceNoList(
81 $this->trans('commands.views.debug.arguments.view-id'),
84 $input->setArgument('view-id', $viewId);
91 protected function execute(InputInterface $input, OutputInterface $output)
93 $io = new DrupalStyle($input, $output);
95 $viewId = $input->getArgument('view-id');
97 $view = $this->entityTypeManager->getStorage('view')->load($viewId);
100 $io->error(sprintf($this->trans('commands.views.debug.messages.not-found'), $viewId));
106 $view->disable()->save();
108 $io->success(sprintf($this->trans('commands.views.disable.messages.disabled-successfully'), $view->get('label')));
109 } catch (\Exception $e) {
110 $io->error($e->getMessage());