Skip to content
Permalink
Browse files

3794 export entities (#3875)

* Add new arguments key and target. Make it possible use not only default target for db connections

* Add universal command to export different bundles. Replace config export content command with chain

* Expose all config entities for export

* Sort config entities in the list
  • Loading branch information...
LOBsTerr committed Mar 19, 2019
1 parent 5f84adb commit e60ecb64a8d8caac98233f8a33ac01d897a043e9
@@ -21,9 +21,14 @@ services:
- { name: drupal.command }
console.config_export_content_type:
class: Drupal\Console\Command\Config\ExportContentTypeCommand
arguments: ['@entity_type.manager', '@config.storage', '@console.extension_manager', '@console.validator']
arguments: ['@console.extension_manager', '@entity_type.manager', '@console.validator', '@console.chain_queue']
tags:
- { name: drupal.command }
console.config_export_entity:
class: Drupal\Console\Command\Config\ExportEntityCommand
arguments: ['@entity_type.manager', '@config.storage', '@console.extension_manager', '@console.validator', '@entity_type.repository']
tags:
- { name: drupal.command }
console.config_export_single:
class: Drupal\Console\Command\Config\ExportSingleCommand
arguments: ['@entity_type.manager', '@config.storage', '@console.extension_manager','@language_manager', '@console.validator']
@@ -9,62 +9,56 @@
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 Drupal\Console\Core\Command\Command;
use Drupal\Core\Config\CachedStorage;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Console\Command\Shared\ExportTrait;
use Drupal\Console\Core\Utils\ChainQueue;
use Drupal\Console\Extension\Manager;
class ExportContentTypeCommand extends Command
{
use ModuleTrait;
use ExportTrait;
/**
* @var EntityTypeManagerInterface
* @var Manager
*/
protected $entityTypeManager;
protected $extensionManager;
/**
* @var CachedStorage
* @var EntityTypeManagerInterface
*/
protected $configStorage;
protected $entityTypeManager;
/**
* @var Manager
* @var Validator
*/
protected $extensionManager;
protected $configExport;
protected $validator;
/**
* @var Validator
* @var ChainQueue
*/
protected $validator;
protected $chainQueue;
/**
* ExportContentTypeCommand constructor.
*
* @param EntityTypeManagerInterface $entityTypeManager
* @param CachedStorage $configStorage
* @param Manager $extensionManager
* @param Validator $validator
* @param Validator $validator
* @param ChainQueue $chainQueue
*/
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
CachedStorage $configStorage,
Manager $extensionManager,
Validator $validator
EntityTypeManagerInterface $entityTypeManager,
Validator $validator,
ChainQueue $chainQueue
) {
$this->entityTypeManager = $entityTypeManager;
$this->configStorage = $configStorage;
$this->extensionManager = $extensionManager;
$this->entityTypeManager = $entityTypeManager;
$this->validator = $validator;
$this->chainQueue = $chainQueue;
parent::__construct();
}
@@ -84,7 +78,7 @@ protected function configure()
)->addOption(
'optional-config',
null,
InputOption::VALUE_OPTIONAL,
InputOption::VALUE_NONE,
$this->trans('commands.config.export.content.type.options.optional-config')
)->addOption(
'remove-uuid',
@@ -114,7 +108,6 @@ protected function interact(InputInterface $input, OutputInterface $output)
$contentType = $input->getArgument('content-type');
if (!$contentType) {
$bundles_entities = $this->entityTypeManager->getStorage('node_type')->loadMultiple();
$bundles = [];
foreach ($bundles_entities as $entity) {
$bundles[$entity->id()] = $entity->label();
}
@@ -163,79 +156,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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, $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, $removeUuid, $removeHash);
$this->getFormDisplays($contentType, $optionalConfig, $removeUuid, $removeHash);
$this->getViewDisplays($contentType, $optionalConfig, $removeUuid, $removeHash);
$this->exportConfigToModule($module, $this->trans('commands.config.export.content.type.messages.content-type-exported'));
}
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, $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];
// Include dependencies in export files
if ($dependencies = $this->fetchDependencies($field_name_config, 'config')) {
$this->resolveDependencies($dependencies, $optional);
}
}
}
}
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, $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];
// Include dependencies in export files
if ($dependencies = $this->fetchDependencies($form_display_name_config, 'config')) {
$this->resolveDependencies($dependencies, $optional);
}
}
}
$this->chainQueue->addCommand(
'config:export:entity', [
'entity-type' => 'node_type',
'bundle' => $contentType,
'--module' => $module,
'--optional-config' => $optionalConfig,
'--remove-uuid' => $removeUuid,
'--remove-config-hash' => $removeHash
]
);
}
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, $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];
// Include dependencies in export files
if ($dependencies = $this->fetchDependencies($view_display_name_config, 'config')) {
$this->resolveDependencies($dependencies, $optional);
}
}
}
}
}

0 comments on commit e60ecb6

Please sign in to comment.
You can’t perform that action at this time.