X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FConfig%2FExportSingleCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FConfig%2FExportSingleCommand.php;h=a3b7288119235c20725e13d185e538172472db09;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Config/ExportSingleCommand.php b/vendor/drupal/console/src/Command/Config/ExportSingleCommand.php new file mode 100644 index 000000000..a3b728811 --- /dev/null +++ b/vendor/drupal/console/src/Command/Config/ExportSingleCommand.php @@ -0,0 +1,289 @@ +entityTypeManager = $entityTypeManager; + $this->configStorage = $configStorage; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('config:export:single') + ->setDescription($this->trans('commands.config.export.single.description')) + ->addOption( + 'name', + '', + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.config.export.single.options.name') + )->addOption( + 'directory', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.config.export.arguments.directory') + )->addOption( + 'module', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.common.options.module') + )->addOption( + 'include-dependencies', + '', + InputOption::VALUE_NONE, + $this->trans('commands.config.export.single.options.include-dependencies') + )->addOption( + 'optional', + '', + InputOption::VALUE_NONE, + $this->trans('commands.config.export.single.options.optional') + )->addOption( + 'remove-uuid', + '', + InputOption::VALUE_NONE, + $this->trans('commands.config.export.single.options.remove-uuid') + )->addOption( + 'remove-config-hash', + '', + InputOption::VALUE_NONE, + $this->trans('commands.config.export.single.options.remove-config-hash') + ); + } + + /* + * Return config types + */ + protected function getConfigTypes() + { + foreach ($this->entityTypeManager->getDefinitions() as $entity_type => $definition) { + if ($definition->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) { + $this->definitions[$entity_type] = $definition; + } + } + $entity_types = array_map( + function ($definition) { + return $definition->getLabel(); + }, $this->definitions + ); + + uasort($entity_types, 'strnatcasecmp'); + $config_types = [ + 'system.simple' => $this->trans('commands.config.export.single.options.simple-configuration'), + ] + $entity_types; + + return $config_types; + } + + /* + * Return config types + */ + protected function getConfigNames($config_type) + { + $names = []; + // For a given entity type, load all entities. + if ($config_type && $config_type !== 'system.simple') { + $entity_storage = $this->entityTypeManager->getStorage($config_type); + foreach ($entity_storage->loadMultiple() as $entity) { + $entity_id = $entity->id(); + $label = $entity->label() ?: $entity_id; + $names[$entity_id] = $label; + } + } + // Handle simple configuration. + else { + // Gather the config entity prefixes. + $config_prefixes = array_map( + function ($definition) { + return $definition->getConfigPrefix() . '.'; + }, $this->definitions + ); + + // Find all config, and then filter our anything matching a config prefix. + $names = $this->configStorage->listAll(); + $names = array_combine($names, $names); + foreach ($names as $config_name) { + foreach ($config_prefixes as $config_prefix) { + if (strpos($config_name, $config_prefix) === 0) { + unset($names[$config_name]); + } + } + } + } + + return $names; + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $config_types = $this->getConfigTypes(); + + $name = $input->getOption('name'); + if (!$name) { + $type = $io->choiceNoList( + $this->trans('commands.config.export.single.questions.config-type'), + array_keys($config_types), + 'system.simple' + ); + $names = $this->getConfigNames($type); + + $name = $io->choiceNoList( + $this->trans('commands.config.export.single.questions.name'), + array_keys($names) + ); + + if ($type !== 'system.simple') { + $definition = $this->entityTypeManager->getDefinition($type); + $name = $definition->getConfigPrefix() . '.' . $name; + } + $input->setOption('name', $name); + } + + $module = $input->getOption('module'); + if ($module) { + $optionalConfig = $input->getOption('optional'); + if (!$optionalConfig) { + $optionalConfig = $io->confirm( + $this->trans('commands.config.export.single.questions.optional'), + true + ); + $input->setOption('optional', $optionalConfig); + } + } + + if (!$input->getOption('remove-uuid')) { + $removeUuid = $io->confirm( + $this->trans('commands.config.export.single.questions.remove-uuid'), + true + ); + $input->setOption('remove-uuid', $removeUuid); + } + if (!$input->getOption('remove-config-hash')) { + $removeHash = $io->confirm( + $this->trans('commands.config.export.single.questions.remove-config-hash'), + true + ); + $input->setOption('remove-config-hash', $removeHash); + } + } + + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $directory = $input->getOption('directory'); + $module = $input->getOption('module'); + $ame = $input->getOption('name'); + $optional = $input->getOption('optional'); + $removeUuid = $input->getOption('remove-uuid'); + $removeHash = $input->getOption('remove-config-hash'); + + foreach ($ame as $nameItem) { + $config = $this->getConfiguration( + $nameItem, + $removeUuid, + $removeHash + ); + + if ($config) { + $this->configExport[$nameItem] = [ + 'data' => $config, + 'optional' => $optional + ]; + + if ($input->getOption('include-dependencies')) { + // Include config dependencies in export files + if ($dependencies = $this->fetchDependencies($config, 'config')) { + $this->resolveDependencies($dependencies, $optional); + } + } + } else { + $io->error($this->trans('commands.config.export.single.messages.config-not-found')); + } + } + + if ($module) { + $this->exportConfigToModule( + $module, + $io, + $this->trans( + 'commands.config.export.single.messages.config-exported' + ) + ); + + return 0; + } + + if (!$directory) { + $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); + } + + $this->exportConfig( + $directory, + $io, + $this->trans('commands.config.export.single.messages.config-exported') + ); + + return 0; + } +}