comparison vendor/chi-teck/drupal-code-generator/src/Helper/QuestionSettersTrait.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2
3 namespace DrupalCodeGenerator\Helper;
4
5 use Symfony\Component\Console\Question\ChoiceQuestion;
6 use Symfony\Component\Console\Question\Question;
7
8 /**
9 * Implements missing Question setters.
10 */
11 trait QuestionSettersTrait {
12
13 /**
14 * Sets question text.
15 *
16 * @param \Symfony\Component\Console\Question\Question $question
17 * The question to update.
18 * @param mixed $question_text
19 * The question text.
20 */
21 protected function setQuestionText(Question $question, $question_text) {
22 // Choice question has a different constructor signature.
23 if ($question instanceof ChoiceQuestion) {
24 $question->__construct($question_text, $question->getChoices(), $question->getDefault());
25 }
26 else {
27 $question->__construct($question_text, $question->getDefault());
28 }
29 }
30
31 /**
32 * Sets question default value.
33 *
34 * @param \Symfony\Component\Console\Question\Question $question
35 * The question to update.
36 * @param mixed $default_value
37 * Default value for the question.
38 */
39 protected function setQuestionDefault(Question $question, $default_value) {
40 if ($question instanceof ChoiceQuestion) {
41 $question->__construct($question->getQuestion(), $question->getChoices(), $default_value);
42 }
43 else {
44 $question->__construct($question->getQuestion(), $default_value);
45 }
46 }
47
48 }