forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigOverrideCommand.php
More file actions
68 lines (57 loc) · 2.25 KB
/
Copy pathConfigOverrideCommand.php
File metadata and controls
68 lines (57 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* @file
* Contains \Drupal\AppConsole\Command\ConfigOverrideCommand.
*/
namespace Drupal\AppConsole\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ConfigOverrideCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('config:override')
->setDescription($this->trans('commands.config.override.description'))
->addArgument('config-name', InputArgument::REQUIRED,
$this->trans('commands.config.override.arguments.config-name'))
->addArgument('key', InputArgument::REQUIRED, $this->trans('commands.config.override.arguments.key'))
->addArgument('value', InputArgument::REQUIRED, $this->trans('commands.config.override.arguments.value'));
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$table = $this->getHelperSet()->get('table');
$configName = $input->getArgument('config-name');
$key = $input->getArgument('key');
$value = $input->getArgument('value');
$config = $this->getConfigFactory()->getEditable($configName);
$configurationOverrideResult = $this->overrideConfiguration($config, $key, $value);
$config->save();
$output->writeln(sprintf(
' <info>%s:</info> <comment>%s</comment>',
$this->trans('commands.config.override.messages.configuration'),
$configName
));
$table->setHeaders(
[
$this->trans('commands.config.override.messages.configuration-key'),
$this->trans('commands.config.override.messages.original'),
$this->trans('commands.config.override.messages.updated'),
]);
$table->setlayout($table::LAYOUT_COMPACT);
$table->setRows($configurationOverrideResult);
$table->render($output);
$config->save();
}
protected function overrideConfiguration($config, $key, $value)
{
$result[] = [
'configuration' => $key,
'original' => $config->get($key),
'updated' => $value,
];
$config->set($key, $value);
return $result;
}
}