Skip to content

Commit 39cd3b8

Browse files
fix error
1 parent b21e145 commit 39cd3b8

5 files changed

+30
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Matthias\SymfonyConsoleForm\Bridge\Transformer;
4+
5+
use Matthias\SymfonyConsoleForm\Console\Formatter\Format;
6+
use Matthias\SymfonyConsoleForm\Form\FormUtil;
7+
use Symfony\Component\Form\FormInterface;
8+
use Symfony\Contracts\Translation\TranslatorInterface;
9+
10+
abstract class AbstractChoiceTransformer extends AbstractTransformer
11+
{
12+
protected function defaultValueFrom(FormInterface $form)
13+
{
14+
$defaultValue = $form->getData();
15+
if (is_array($defaultValue)) {
16+
$defaultValue = implode(',', $defaultValue);
17+
}
18+
19+
return $defaultValue;
20+
}
21+
}

src/Bridge/Transformer/AbstractTextInputBasedTransformer.php

+5
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ public function transform(FormInterface $form): Question
1313
{
1414
return new Question($this->questionFrom($form), $this->defaultValueFrom($form));
1515
}
16+
17+
protected function defaultValueFrom(FormInterface $form)
18+
{
19+
return $form->getViewData();
20+
}
1621
}

src/Bridge/Transformer/AbstractTransformer.php

+2-13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public function __construct(TranslatorInterface $translator)
2222
$this->translator = $translator;
2323
}
2424

25+
abstract protected function defaultValueFrom(FormInterface $form);
26+
2527
protected function questionFrom(FormInterface $form): string
2628
{
2729
$translationDomain = $this->translationDomainFrom($form);
@@ -34,19 +36,6 @@ protected function questionFrom(FormInterface $form): string
3436
return $this->formattedQuestion($question, $this->defaultValueFrom($form), $help);
3537
}
3638

37-
/**
38-
* @return mixed
39-
*/
40-
protected function defaultValueFrom(FormInterface $form)
41-
{
42-
$defaultValue = $form->getData();
43-
if (is_array($defaultValue)) {
44-
$defaultValue = implode(',', $defaultValue);
45-
}
46-
47-
return $defaultValue;
48-
}
49-
5039
protected function translationDomainFrom(FormInterface $form): ?string
5140
{
5241
while ((null === $domain = $form->getConfig()->getOption('translation_domain')) && $form->getParent()) {

src/Bridge/Transformer/CheckboxTransformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Symfony\Component\Console\Question\Question;
77
use Symfony\Component\Form\FormInterface;
88

9-
final class CheckboxTransformer extends AbstractTransformer
9+
final class CheckboxTransformer extends AbstractChoiceTransformer
1010
{
1111
public function transform(FormInterface $form): Question
1212
{

src/Bridge/Transformer/ChoiceTransformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
88
use Symfony\Component\Form\FormInterface;
99

10-
final class ChoiceTransformer extends AbstractTransformer
10+
final class ChoiceTransformer extends AbstractChoiceTransformer
1111
{
1212
public function transform(FormInterface $form): Question
1313
{

0 commit comments

Comments
 (0)