Skip to content

Commit bcb4f09

Browse files
committed
Fixed SymfonyQuestionHelper multi-choice with defaults
1 parent 14d48a1 commit bcb4f09

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Symfony/Component/Console/Helper/SymfonyQuestionHelper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ protected function writePrompt(OutputInterface $output, Question $question)
6767

6868
break;
6969

70+
case $question instanceof ChoiceQuestion && $question->isMultiSelect():
71+
$choices = $question->getChoices();
72+
$default = explode(',', $default);
73+
74+
foreach ($default as &$defaultVal) {
75+
$defaultVal = $choices[$defaultVal];
76+
}
77+
78+
unset($defaultVal);
79+
80+
$text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, implode(', ', $default));
81+
82+
break;
83+
7084
case $question instanceof ChoiceQuestion:
7185
$choices = $question->getChoices();
7286
$text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $choices[$default]);

src/Symfony/Component/Console/Question/ChoiceQuestion.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public function setMultiselect($multiselect)
6868
return $this;
6969
}
7070

71+
/**
72+
* Returns whether the choices are multiselect.
73+
*
74+
* @return bool
75+
*/
76+
public function isMultiselect()
77+
{
78+
return $this->multiselect;
79+
}
80+
7181
/**
7282
* Gets the prompt for choices.
7383
*

0 commit comments

Comments
 (0)