Skip to content

Commit 236337b

Browse files
committed
Added validation for single-valued properties.
1 parent 56d3e37 commit 236337b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Drush/Commands/CodeBuilderDrushCommands.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,31 @@ protected function interactCollectProperties(DataItem $data, $breadcrumb): void
552552
$data->set($value);
553553
}
554554
else {
555+
if ($validators = $data->getValidators()) {
556+
$validation = function ($value) use ($data) {
557+
$data->set($value);
558+
$violations = $data->validate();
559+
if (empty($violations)) {
560+
return NULL;
561+
}
562+
563+
$messages = [];
564+
foreach ($violations as $address => $violation_messages) {
565+
foreach ($violation_messages as $violation_message) {
566+
$messages[] = $violation_message;
567+
}
568+
}
569+
return implode(', ', $messages);
570+
};
571+
}
572+
555573
$data->applyDefault();
556574

557575
$value = text(
558576
label: "Enter the {$data->getLabel()}",
559577
required: $data->isRequired(),
560578
default: $data->value ?? '',
579+
validate: $validation,
561580
);
562581

563582
if (!empty($value)) {

0 commit comments

Comments
 (0)