Skip to content

Commit

Permalink
add --remove-uuid and --remove-config-hash to config:export:content:t…
Browse files Browse the repository at this point in the history
…ype - fixes #3622 (#3623)
  • Loading branch information
malcomio authored and jmolivas committed Jan 7, 2018
1 parent d1b230f commit 317211a
Showing 1 changed file with 57 additions and 27 deletions.
84 changes: 57 additions & 27 deletions src/Command/Config/ExportContentTypeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class ExportContentTypeCommand extends Command
* @param Manager $extensionManager
*/
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
CachedStorage $configStorage,
Manager $extensionManager
EntityTypeManagerInterface $entityTypeManager,
CachedStorage $configStorage,
Manager $extensionManager
) {
$this->entityTypeManager = $entityTypeManager;
$this->configStorage = $configStorage;
Expand All @@ -65,20 +65,30 @@ public function __construct(
protected function configure()
{
$this
->setName('config:export:content:type')
->setDescription($this->trans('commands.config.export.content.type.description'))
->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
->addArgument(
'content-type',
InputArgument::REQUIRED,
$this->trans('commands.config.export.content.type.arguments.content-type')
)->addOption(
'optional-config',
null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.config.export.content.type.options.optional-config')
)
->setAliases(['cect']);
->setName('config:export:content:type')
->setDescription($this->trans('commands.config.export.content.type.description'))
->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
->addArgument(
'content-type',
InputArgument::REQUIRED,
$this->trans('commands.config.export.content.type.arguments.content-type')
)->addOption(
'optional-config',
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 = [];
}
Expand Down Expand Up @@ -122,6 +132,23 @@ protected function interact(InputInterface $input, OutputInterface $output)
);
}
$input->setOption('optional-config', $optionalConfig);


if (!$input->getOption('remove-uuid')) {
$removeUuid = $io->confirm(
$this->trans('commands.config.export.content.type.questions.remove-uuid'),
true
);
$input->setOption('remove-uuid', $removeUuid);
}
if (!$input->getOption('remove-config-hash')) {
$removeHash = $io->confirm(
$this->trans('commands.config.export.content.type.questions.remove-config-hash'),
true
);
$input->setOption('remove-config-hash', $removeHash);
}

}

/**
Expand All @@ -134,31 +161,34 @@ protected function execute(InputInterface $input, OutputInterface $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);

$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'));
}

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];
Expand All @@ -170,13 +200,13 @@ protected function getFields($contentType, $optional = false)
}
}

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];
Expand All @@ -188,13 +218,13 @@ protected function getFormDisplays($contentType, $optional = false)
}
}

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];
Expand Down

0 comments on commit 317211a

Please sign in to comment.