use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Command\Command;
+use Drupal\Console\Core\Command\Command;
+use Drupal\Console\Utils\Validator;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Config\CachedStorage;
-use Drupal\Console\Core\Style\DrupalStyle;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
use Drupal\Console\Command\Shared\ExportTrait;
+use Drupal\Console\Command\Shared\ModuleTrait;
use Drupal\Console\Extension\Manager;
+use Drupal\Core\Language\LanguageManagerInterface;
+use Webmozart\PathUtil\Path;
class ExportSingleCommand extends Command
{
- use CommandTrait;
+ use ModuleTrait;
use ExportTrait;
/**
*/
protected $configStorage;
+ /**
+ * @var Manager
+ */
+ protected $extensionManager;
+
+ /**
+ * @var Configuration.
+ */
protected $configExport;
+ /**
+ * @var LanguageManagerInterface
+ */
+ protected $languageManager;
+
+ /**
+ * @var Validator
+ */
+ protected $validator;
+
/**
* ExportSingleCommand constructor.
*
* @param EntityTypeManagerInterface $entityTypeManager
* @param CachedStorage $configStorage
* @param Manager $extensionManager
+ * @param languageManager $languageManager
+ * @param Validator $validator
*/
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
CachedStorage $configStorage,
- Manager $extensionManager
+ Manager $extensionManager,
+ LanguageManagerInterface $languageManager,
+ Validator $validator
) {
$this->entityTypeManager = $entityTypeManager;
$this->configStorage = $configStorage;
$this->extensionManager = $extensionManager;
+ $this->languageManager = $languageManager;
+ $this->validator = $validator;
parent::__construct();
}
null,
InputOption::VALUE_NONE,
$this->trans('commands.config.export.single.options.remove-config-hash')
- );
+ )
+ ->setAliases(['ces']);
}
/*
uasort($entity_types, 'strnatcasecmp');
$config_types = [
- 'system.simple' => $this->trans('commands.config.export.single.options.simple-configuration'),
- ] + $entity_types;
+ 'system.simple' => $this->trans('commands.config.export.single.options.simple-configuration'),
+ ] + $entity_types;
return $config_types;
}
*/
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(
+ $type = $this->getIo()->choiceNoList(
$this->trans('commands.config.export.single.questions.config-type'),
array_keys($config_types),
'system.simple'
);
$names = $this->getConfigNames($type);
- $name = $io->choiceNoList(
+ $name = $this->getIo()->choiceNoList(
$this->trans('commands.config.export.single.questions.name'),
array_keys($names)
);
$definition = $this->entityTypeManager->getDefinition($type);
$name = $definition->getConfigPrefix() . '.' . $name;
}
- $input->setOption('name', $name);
+
+ $input->setOption('name', [$name]);
}
- $module = $input->getOption('module');
+ // --module option
+ $module = $this->getModuleOption();
if ($module) {
$optionalConfig = $input->getOption('optional');
if (!$optionalConfig) {
- $optionalConfig = $io->confirm(
+ $optionalConfig = $this->getIo()->confirm(
$this->trans('commands.config.export.single.questions.optional'),
true
);
}
if (!$input->getOption('remove-uuid')) {
- $removeUuid = $io->confirm(
+ $removeUuid = $this->getIo()->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(
+ $removeHash = $this->getIo()->confirm(
$this->trans('commands.config.export.single.questions.remove-config-hash'),
true
);
}
}
-
/**
* {@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');
+ $name = $input->getOption('name');
$optional = $input->getOption('optional');
$removeUuid = $input->getOption('remove-uuid');
$removeHash = $input->getOption('remove-config-hash');
+ $includeDependencies = $input->getOption('include-dependencies');
+
+ foreach ($this->getLanguage() as $value) {
+ foreach ($name as $nameItem) {
+ $config = $this->getConfiguration(
+ $nameItem,
+ $removeUuid,
+ $removeHash,
+ $value
+ );
- 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);
+ if ($config) {
+ $this->configExport[$nameItem] = [
+ 'data' => $config,
+ 'optional' => $optional
+ ];
+
+ if ($includeDependencies) {
+ // Include config dependencies in export files
+ if ($dependencies = $this->fetchDependencies($config, 'config')) {
+ $this->resolveDependencies($dependencies, $optional);
+ }
}
+ } else {
+ $this->getIo()->error($this->trans('commands.config.export.single.messages.config-not-found'));
}
- } 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'
- )
- );
+ if ($module) {
+ $this->exportConfigToModule(
+ $module,
+ $this->trans(
+ 'commands.config.export.single.messages.config-exported'
+ )
+ );
- return 0;
- }
+ return 0;
+ }
- if (!$directory) {
- $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
- }
+ if (!is_dir($directory)) {
+ $directory = $directory_copy = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
+ if ($value) {
+ $directory = $directory_copy .'/' . str_replace('.', '/', $value);
+ }
+ } else {
+ $directory = $directory_copy .'/' . str_replace('.', '/', $value);
+ $directory = Path::canonicalize($directory);
+ if (!file_exists($directory)) {
+ mkdir($directory, 0755, true);
+ }
+ }
- $this->exportConfig(
- $directory,
- $io,
- $this->trans('commands.config.export.single.messages.config-exported')
- );
+ $this->exportConfig(
+ $directory,
+ $this->trans('commands.config.export.single.messages.config-exported')
+ );
+ }
return 0;
}
+
+ /**
+ * Get the languague enable.
+ */
+ protected function getLanguage()
+ {
+ $output = [];
+ // Get the language that be for default.
+ $default_id = $this->languageManager->getDefaultLanguage()->getId();
+ foreach ($this->languageManager->getLanguages() as $key => $value) {
+ if ($default_id == $key) {
+ $output[] = '';
+ } else {
+ $output[] = 'language.' . $value->getId();
+ }
+ }
+ return $output;
+ }
}