8000 Fixed SymfonyQuestionHelper multi-choice with defaults · symfony/symfony@53a0c38 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 script crossorigin="anonymous" type="application/javascript" src="https://github.githubassets.com/assets/vendors-node_modules_github_remote-form_dist_index_js-node_modules_delegated-events_dist_inde-94fd67-99b04cc350b5.js" defer="defer">

Commit 53a0c38

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

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
@@ -109,6 +109,16 @@ public function setErrorMessage($errorMessage)
109109
return $this;
110110
}
111111

112+
/**
113+
* Returns whether the choices are multiselect.
114+
*
115+
* @return bool
116+
*/
117+
public function isMultiSelect()
118+
{
119+
return $this->multiselect;
120+
}
121+
112122
/**
113123
* Returns the default answer validator.
114124
*

0 commit comments

Comments
 (0)
0