5 * Contains \Drupal\Console\Command\Views\EnableCommand.
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\Config\Definition\Exception\Exception;
14 use Symfony\Component\Console\Command\Command;
15 use Drupal\Console\Core\Command\Shared\CommandTrait;
16 use Drupal\Core\Entity\EntityTypeManagerInterface;
17 use Drupal\Core\Entity\Query\QueryFactory;
18 use Drupal\Console\Core\Style\DrupalStyle;
23 * @package Drupal\Console\Command\Views
25 class EnableCommand extends Command
30 * @var EntityTypeManagerInterface
32 protected $entityTypeManager;
37 protected $entityQuery;
40 * EnableCommand constructor.
42 * @param EntityTypeManagerInterface $entityTypeManager
43 * @param QueryFactory $entityQuery
45 public function __construct(
46 EntityTypeManagerInterface $entityTypeManager,
47 QueryFactory $entityQuery
49 $this->entityTypeManager = $entityTypeManager;
50 $this->entityQuery = $entityQuery;
51 parent::__construct();
57 protected function configure()
60 ->setName('views:enable')
61 ->setDescription($this->trans('commands.views.enable.description'))
64 InputArgument::OPTIONAL,
65 $this->trans('commands.views.debug.arguments.view-id')
72 protected function interact(InputInterface $input, OutputInterface $output)
74 $io = new DrupalStyle($input, $output);
75 $viewId = $input->getArgument('view-id');
77 $views = $this->entityQuery
79 ->condition('status', 0)
81 $viewId = $io->choiceNoList(
82 $this->trans('commands.views.debug.arguments.view-id'),
85 $input->setArgument('view-id', $viewId);
92 protected function execute(InputInterface $input, OutputInterface $output)
94 $io = new DrupalStyle($input, $output);
95 $viewId = $input->getArgument('view-id');
97 $view = $this->entityTypeManager->getStorage('view')->load($viewId);
102 $this->trans('commands.views.debug.messages.not-found'),
110 $view->enable()->save();
113 $this->trans('commands.views.enable.messages.enabled-successfully'),
117 } catch (Exception $e) {
118 $io->error($e->getMessage());