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 Drupal\Console\Core\Command\Command;
14 use Drupal\Core\Entity\EntityTypeManagerInterface;
15 use Drupal\Core\Entity\Query\QueryFactory;
18 * Class DisableCommand
20 * @package Drupal\Console\Command\Views
22 class DisableCommand extends Command
25 * @var EntityTypeManagerInterface
27 protected $entityTypeManager;
32 protected $entityQuery;
35 * DisableCommand constructor.
37 * @param EntityTypeManagerInterface $entityTypeManager
38 * @param QueryFactory $entityQuery
40 public function __construct(
41 EntityTypeManagerInterface $entityTypeManager,
42 QueryFactory $entityQuery
44 $this->entityTypeManager = $entityTypeManager;
45 $this->entityQuery = $entityQuery;
46 parent::__construct();
52 protected function configure()
55 ->setName('views:disable')
56 ->setDescription($this->trans('commands.views.disable.description'))
59 InputArgument::OPTIONAL,
60 $this->trans('commands.debug.views.arguments.view-id')
68 protected function interact(InputInterface $input, OutputInterface $output)
70 $viewId = $input->getArgument('view-id');
72 $views = $this->entityQuery
74 ->condition('status', 1)
76 $viewId = $this->getIo()->choiceNoList(
77 $this->trans('commands.debug.views.arguments.view-id'),
80 $input->setArgument('view-id', $viewId);
87 protected function execute(InputInterface $input, OutputInterface $output)
89 $viewId = $input->getArgument('view-id');
91 $view = $this->entityTypeManager->getStorage('view')->load($viewId);
94 $this->getIo()->error(sprintf($this->trans('commands.debug.views.messages.not-found'), $viewId));
100 $view->disable()->save();
102 $this->getIo()->success(sprintf($this->trans('commands.views.disable.messages.disabled-successfully'), $view->get('label')));
103 } catch (\Exception $e) {
104 $this->getIo()->error($e->getMessage());