5 * Contains \Drupal\Console\Command\Config\ExportViewCommand.
8 namespace Drupal\Console\Command\Config;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Drupal\Console\Core\Command\Command;
15 use Drupal\Console\Utils\Validator;
16 use Drupal\Console\Command\Shared\ModuleTrait;
17 use Drupal\Core\Entity\EntityTypeManagerInterface;
18 use Drupal\Core\Config\CachedStorage;
19 use Drupal\Console\Command\Shared\ExportTrait;
20 use Drupal\Console\Extension\Manager;
22 class ExportViewCommand extends Command
27 protected $configExport;
31 * @var EntityTypeManagerInterface
33 protected $entityTypeManager;
38 protected $configStorage;
43 protected $extensionManager;
51 * ExportViewCommand constructor.
53 * @param EntityTypeManagerInterface $entityTypeManager
54 * @param CachedStorage $configStorage
55 * @param Manager $extensionManager
57 public function __construct(
58 EntityTypeManagerInterface $entityTypeManager,
59 CachedStorage $configStorage,
60 Manager $extensionManager,
63 $this->entityTypeManager = $entityTypeManager;
64 $this->configStorage = $configStorage;
65 $this->extensionManager = $extensionManager;
66 $this->validator = $validator;
67 parent::__construct();
71 protected function configure()
74 ->setName('config:export:view')
75 ->setDescription($this->trans('commands.config.export.view.description'))
78 InputOption::VALUE_REQUIRED,
79 $this->trans('commands.common.options.module')
83 InputArgument::OPTIONAL,
84 $this->trans('commands.config.export.view.arguments.view-id')
89 InputOption::VALUE_OPTIONAL,
90 $this->trans('commands.config.export.view.options.optional-config')
93 'include-module-dependencies',
95 InputOption::VALUE_OPTIONAL,
96 $this->trans('commands.config.export.view.options.include-module-dependencies')
98 ->setAliases(['cev']);
104 protected function interact(InputInterface $input, OutputInterface $output)
107 $this->getModuleOption();
110 $viewId = $input->getArgument('view-id');
112 $views = $this->entityTypeManager->getStorage('view')->loadMultiple();
115 foreach ($views as $view) {
116 $viewList[$view->get('id')] = $view->get('label');
119 $viewId = $this->getIo()->choiceNoList(
120 $this->trans('commands.config.export.view.questions.view'),
123 $input->setArgument('view-id', $viewId);
126 $optionalConfig = $input->getOption('optional-config');
127 if (!$optionalConfig) {
128 $optionalConfig = $this->getIo()->confirm(
129 $this->trans('commands.config.export.view.questions.optional-config'),
132 $input->setOption('optional-config', $optionalConfig);
135 $includeModuleDependencies = $input->getOption('include-module-dependencies');
136 if (!$includeModuleDependencies) {
137 $includeModuleDependencies = $this->getIo()->confirm(
138 $this->trans('commands.config.export.view.questions.include-module-dependencies'),
141 $input->setOption('include-module-dependencies', $includeModuleDependencies);
145 protected function execute(InputInterface $input, OutputInterface $output)
147 $module = $input->getOption('module');
148 $viewId = $input->getArgument('view-id');
149 $optionalConfig = $input->getOption('optional-config');
150 $includeModuleDependencies = $input->getOption('include-module-dependencies');
152 $viewTypeDefinition = $this->entityTypeManager->getDefinition('view');
153 $viewTypeName = $viewTypeDefinition->getConfigPrefix() . '.' . $viewId;
155 $viewNameConfig = $this->getConfiguration($viewTypeName);
157 $this->configExport[$viewTypeName] = ['data' => $viewNameConfig, 'optional' => $optionalConfig];
159 // Include config dependencies in export files
160 if ($dependencies = $this->fetchDependencies($viewNameConfig, 'config')) {
161 $this->resolveDependencies($dependencies, $optionalConfig);
164 // Include module dependencies in export files if export is not optional
165 if ($includeModuleDependencies) {
166 if ($dependencies = $this->fetchDependencies($viewNameConfig, 'module')) {
167 $this->exportModuleDependencies($module, $dependencies);
171 $this->exportConfigToModule($module, $this->trans('commands.views.export.messages.view-exported'));