5 * Contains \Drupal\Console\Command\Config\OverrideCommand.
8 namespace Drupal\Console\Command\Config;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Core\Config\CachedStorage;
15 use Drupal\Core\Config\ConfigFactory;
16 use Drupal\Console\Core\Command\Shared\CommandTrait;
17 use Drupal\Console\Core\Style\DrupalStyle;
19 class OverrideCommand extends Command
26 protected $configStorage;
31 protected $configFactory;
34 * OverrideCommand constructor.
36 * @param CachedStorage $configStorage
37 * @param ConfigFactory $configFactory
39 public function __construct(
40 CachedStorage $configStorage,
41 ConfigFactory $configFactory
43 $this->configStorage = $configStorage;
44 $this->configFactory = $configFactory;
45 parent::__construct();
48 protected function configure()
51 ->setName('config:override')
52 ->setDescription($this->trans('commands.config.override.description'))
55 InputArgument::REQUIRED,
56 $this->trans('commands.config.override.arguments.name')
58 ->addArgument('key', InputArgument::REQUIRED, $this->trans('commands.config.override.arguments.key'))
59 ->addArgument('value', InputArgument::REQUIRED, $this->trans('commands.config.override.arguments.value'));
65 protected function interact(InputInterface $input, OutputInterface $output)
67 $io = new DrupalStyle($input, $output);
68 $name = $input->getArgument('name');
69 $names = $this->configFactory->listAll();
71 if (!in_array($name, $names)) {
74 $this->trans('commands.config.override.messages.invalid-name'),
82 $name = $io->choiceNoList(
83 $this->trans('commands.config.override.questions.name'),
86 $input->setArgument('name', $name);
88 $key = $input->getArgument('key');
90 if ($this->configStorage->exists($name)) {
91 $configuration = $this->configStorage->read($name);
93 $key = $io->choiceNoList(
94 $this->trans('commands.config.override.questions.key'),
95 array_keys($configuration)
97 $input->setArgument('key', $key);
99 $value = $input->getArgument('value');
102 $this->trans('commands.config.override.questions.value')
104 $input->setArgument('value', $value);
110 protected function execute(InputInterface $input, OutputInterface $output)
112 $io = new DrupalStyle($input, $output);
114 $configName = $input->getArgument('name');
115 $key = $input->getArgument('key');
116 $value = $input->getArgument('value');
118 $config = $this->configFactory->getEditable($configName);
120 $configurationOverrideResult = $this->overrideConfiguration($config, $key, $value);
124 $io->info($this->trans('commands.config.override.messages.configuration'), false);
125 $io->comment($configName);
128 $this->trans('commands.config.override.messages.configuration-key'),
129 $this->trans('commands.config.override.messages.original'),
130 $this->trans('commands.config.override.messages.updated'),
132 $tableRows = $configurationOverrideResult;
133 $io->table($tableHeader, $tableRows);
139 protected function overrideConfiguration($config, $key, $value)
142 'configuration' => $key,
143 'original' => $config->get($key),
146 $config->set($key, $value);