X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FConfig%2FExportContentTypeCommand.php;h=93b52c230ec15d4bcba3c18162d54f9bc6c6d8eb;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=6382238f3ebc1230fe5aae58cfdd3d957fc77b41;hpb=eba34333e3c89f208d2f72fa91351ad019a71583;p=yaffs-website diff --git a/vendor/drupal/console/src/Command/Config/ExportContentTypeCommand.php b/vendor/drupal/console/src/Command/Config/ExportContentTypeCommand.php index 6382238f3..93b52c230 100644 --- a/vendor/drupal/console/src/Command/Config/ExportContentTypeCommand.php +++ b/vendor/drupal/console/src/Command/Config/ExportContentTypeCommand.php @@ -8,21 +8,20 @@ namespace Drupal\Console\Command\Config; use Drupal\Console\Command\Shared\ModuleTrait; +use Drupal\Console\Utils\Validator; +use Symfony\Component\Console\Exception\InvalidOptionException; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Command\Command; +use Drupal\Console\Core\Command\Command; use Drupal\Core\Config\CachedStorage; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Console\Core\Command\Shared\CommandTrait; -use Drupal\Console\Core\Style\DrupalStyle; use Drupal\Console\Command\Shared\ExportTrait; use Drupal\Console\Extension\Manager; class ExportContentTypeCommand extends Command { - use CommandTrait; use ModuleTrait; use ExportTrait; @@ -43,21 +42,29 @@ class ExportContentTypeCommand extends Command protected $configExport; + /** + * @var Validator + */ + protected $validator; + /** * ExportContentTypeCommand constructor. * * @param EntityTypeManagerInterface $entityTypeManager * @param CachedStorage $configStorage * @param Manager $extensionManager + * @param Validator $validator */ public function __construct( EntityTypeManagerInterface $entityTypeManager, CachedStorage $configStorage, - Manager $extensionManager + Manager $extensionManager, + Validator $validator ) { $this->entityTypeManager = $entityTypeManager; $this->configStorage = $configStorage; $this->extensionManager = $extensionManager; + $this->validator = $validator; parent::__construct(); } @@ -79,7 +86,18 @@ class ExportContentTypeCommand extends Command null, InputOption::VALUE_OPTIONAL, $this->trans('commands.config.export.content.type.options.optional-config') - ); + )->addOption( + 'remove-uuid', + null, + InputOption::VALUE_NONE, + $this->trans('commands.config.export.content.type.options.remove-uuid') + )->addOption( + 'remove-config-hash', + null, + InputOption::VALUE_NONE, + $this->trans('commands.config.export.content.type.options.remove-config-hash') + ) + ->setAliases(['cect']); $this->configExport = []; } @@ -89,15 +107,8 @@ class ExportContentTypeCommand extends Command */ 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); + $this->getModuleOption(); // --content-type argument $contentType = $input->getArgument('content-type'); @@ -108,7 +119,7 @@ class ExportContentTypeCommand extends Command $bundles[$entity->id()] = $entity->label(); } - $contentType = $io->choice( + $contentType = $this->getIo()->choice( $this->trans('commands.config.export.content.type.questions.content-type'), $bundles ); @@ -117,12 +128,28 @@ class ExportContentTypeCommand extends Command $optionalConfig = $input->getOption('optional-config'); if (!$optionalConfig) { - $optionalConfig = $io->confirm( + $optionalConfig = $this->getIo()->confirm( $this->trans('commands.config.export.content.type.questions.optional-config'), true ); } $input->setOption('optional-config', $optionalConfig); + + + if (!$input->getOption('remove-uuid')) { + $removeUuid = $this->getIo()->confirm( + $this->trans('commands.config.export.content.type.questions.remove-uuid'), + true + ); + $input->setOption('remove-uuid', $removeUuid); + } + if (!$input->getOption('remove-config-hash')) { + $removeHash = $this->getIo()->confirm( + $this->trans('commands.config.export.content.type.questions.remove-config-hash'), + true + ); + $input->setOption('remove-config-hash', $removeHash); + } } /** @@ -130,36 +157,41 @@ class ExportContentTypeCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $io = new DrupalStyle($input, $output); - $module = $input->getOption('module'); $contentType = $input->getArgument('content-type'); $optionalConfig = $input->getOption('optional-config'); + $removeUuid = $input->getOption('remove-uuid'); + $removeHash = $input->getOption('remove-config-hash'); $contentTypeDefinition = $this->entityTypeManager->getDefinition('node_type'); $contentTypeName = $contentTypeDefinition->getConfigPrefix() . '.' . $contentType; - $contentTypeNameConfig = $this->getConfiguration($contentTypeName); + $contentTypeNameConfig = $this->getConfiguration($contentTypeName, $removeUuid, $removeHash); + + if (empty($contentTypeNameConfig)) { + throw new InvalidOptionException(sprintf('The content type %s does not exist.', $contentType)); + } $this->configExport[$contentTypeName] = ['data' => $contentTypeNameConfig, 'optional' => $optionalConfig]; - $this->getFields($contentType, $optionalConfig); + $this->getFields($contentType, $optionalConfig, $removeUuid, $removeHash); - $this->getFormDisplays($contentType, $optionalConfig); + $this->getFormDisplays($contentType, $optionalConfig, $removeUuid, $removeHash); - $this->getViewDisplays($contentType, $optionalConfig); + $this->getViewDisplays($contentType, $optionalConfig, $removeUuid, $removeHash); - $this->exportConfigToModule($module, $io, $this->trans('commands.config.export.content.type.messages.content_type_exported')); + $this->exportConfigToModule($module, $this->trans('commands.config.export.content.type.messages.content-type-exported')); } - protected function getFields($contentType, $optional = false) + protected function getFields($contentType, $optional = false, $removeUuid = false, $removeHash = false) { $fields_definition = $this->entityTypeManager->getDefinition('field_config'); $fields_storage = $this->entityTypeManager->getStorage('field_config'); foreach ($fields_storage->loadMultiple() as $field) { $field_name = $fields_definition->getConfigPrefix() . '.' . $field->id(); - $field_name_config = $this->getConfiguration($field_name); + $field_name_config = $this->getConfiguration($field_name, $removeUuid, $removeHash); + // Only select fields related with content type if ($field_name_config['bundle'] == $contentType) { $this->configExport[$field_name] = ['data' => $field_name_config, 'optional' => $optional]; @@ -171,13 +203,13 @@ class ExportContentTypeCommand extends Command } } - protected function getFormDisplays($contentType, $optional = false) + protected function getFormDisplays($contentType, $optional = false, $removeUuid = false, $removeHash = false) { $form_display_definition = $this->entityTypeManager->getDefinition('entity_form_display'); $form_display_storage = $this->entityTypeManager->getStorage('entity_form_display'); foreach ($form_display_storage->loadMultiple() as $form_display) { $form_display_name = $form_display_definition->getConfigPrefix() . '.' . $form_display->id(); - $form_display_name_config = $this->getConfiguration($form_display_name); + $form_display_name_config = $this->getConfiguration($form_display_name, $removeUuid, $removeHash); // Only select fields related with content type if ($form_display_name_config['bundle'] == $contentType) { $this->configExport[$form_display_name] = ['data' => $form_display_name_config, 'optional' => $optional]; @@ -189,13 +221,13 @@ class ExportContentTypeCommand extends Command } } - protected function getViewDisplays($contentType, $optional = false) + protected function getViewDisplays($contentType, $optional = false, $removeUuid = false, $removeHash = false) { $view_display_definition = $this->entityTypeManager->getDefinition('entity_view_display'); $view_display_storage = $this->entityTypeManager->getStorage('entity_view_display'); foreach ($view_display_storage->loadMultiple() as $view_display) { $view_display_name = $view_display_definition->getConfigPrefix() . '.' . $view_display->id(); - $view_display_name_config = $this->getConfiguration($view_display_name); + $view_display_name_config = $this->getConfiguration($view_display_name, $removeUuid, $removeHash); // Only select fields related with content type if ($view_display_name_config['bundle'] == $contentType) { $this->configExport[$view_display_name] = ['data' => $view_display_name_config, 'optional' => $optional];