X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FConfig%2FExportViewCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FConfig%2FExportViewCommand.php;h=246b09e268a69f169b42895098f7864939fc12ff;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/drupal/console/src/Command/Config/ExportViewCommand.php b/vendor/drupal/console/src/Command/Config/ExportViewCommand.php new file mode 100644 index 000000000..246b09e26 --- /dev/null +++ b/vendor/drupal/console/src/Command/Config/ExportViewCommand.php @@ -0,0 +1,176 @@ +entityTypeManager = $entityTypeManager; + $this->configStorage = $configStorage; + $this->extensionManager = $extensionManager; + parent::__construct(); + } + + + protected function configure() + { + $this + ->setName('config:export:view') + ->setDescription($this->trans('commands.config.export.view.description')) + ->addOption( + 'module', '', + InputOption::VALUE_REQUIRED, + $this->trans('commands.common.options.module') + ) + ->addArgument( + 'view-id', + InputArgument::OPTIONAL, + $this->trans('commands.config.export.view.arguments.view-id') + ) + ->addOption( + 'optional-config', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.config.export.view.options.optional-config') + ) + ->addOption( + 'include-module-dependencies', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.config.export.view.options.include-module-dependencies') + ); + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + // --module option + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $input->setOption('module', $module); + } + + // view-id argument + $viewId = $input->getArgument('view-id'); + if (!$viewId) { + $views = $this->entityTypeManager->getStorage('view')->loadMultiple(); + + $viewList = []; + foreach ($views as $view) { + $viewList[$view->get('id')] = $view->get('label'); + } + + $viewId = $io->choiceNoList( + $this->trans('commands.config.export.view.questions.view'), + $viewList + ); + $input->setArgument('view-id', $viewId); + } + + $optionalConfig = $input->getOption('optional-config'); + if (!$optionalConfig) { + $optionalConfig = $io->confirm( + $this->trans('commands.config.export.view.questions.optional-config'), + true + ); + $input->setOption('optional-config', $optionalConfig); + } + + $includeModuleDependencies = $input->getOption('include-module-dependencies'); + if (!$includeModuleDependencies) { + $includeModuleDependencies = $io->confirm( + $this->trans('commands.config.export.view.questions.include-module-dependencies'), + true + ); + $input->setOption('include-module-dependencies', $includeModuleDependencies); + } + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $module = $input->getOption('module'); + $viewId = $input->getArgument('view-id'); + $optionalConfig = $input->getOption('optional-config'); + $includeModuleDependencies = $input->getOption('include-module-dependencies'); + + $viewTypeDefinition = $this->entityTypeManager->getDefinition('view'); + $viewTypeName = $viewTypeDefinition->getConfigPrefix() . '.' . $viewId; + + $viewNameConfig = $this->getConfiguration($viewTypeName); + + $this->configExport[$viewTypeName] = ['data' => $viewNameConfig, 'optional' => $optionalConfig]; + + // Include config dependencies in export files + if ($dependencies = $this->fetchDependencies($viewNameConfig, 'config')) { + $this->resolveDependencies($dependencies, $optionalConfig); + } + + // Include module dependencies in export files if export is not optional + if ($includeModuleDependencies) { + if ($dependencies = $this->fetchDependencies($viewNameConfig, 'module')) { + $this->exportModuleDependencies($io, $module, $dependencies); + } + } + + $this->exportConfigToModule($module, $io, $this->trans('commands.views.export.messages.view_exported')); + } +}