function ConsoleInputCollector::collectValue
Overrides InputCollectorInterface::collectValue
File
-
core/
lib/ Drupal/ Core/ Recipe/ ConsoleInputCollector.php, line 77
Class
- ConsoleInputCollector
- Collects input values for recipes from the command line.
Namespace
Drupal\Core\RecipeCode
public function collectValue(string $name, DataDefinitionInterface $definition, mixed $default_value) : mixed {
$option_values = $this->getInputFromOptions();
// If the value was passed as a `--input` option, return that.
if (array_key_exists($name, $option_values)) {
return $option_values[$name];
}
/** @var array{method: string, arguments?: array<mixed>}|null $settings */
$settings = $definition->getSetting('prompt');
// If there's no information on how to prompt the user, there's nothing else
// for us to do; return the default value.
if (empty($settings)) {
return $default_value;
}
$method = $settings['method'];
$arguments = $settings['arguments'] ?? [];
// Most of the input-collecting methods of StyleInterface have a `default`
// parameter.
$arguments += [
'default' => $default_value,
];
// We don't support using Symfony Console's inline validation; instead,
// input definitions should define constraints.
unset($arguments['validator']);
return $this->io
->{$method}(...$arguments);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.