Skip to content

Commit fb24f91

Browse files
authored
Merge pull request #158 from cristoforocervino/symfony-placeholder-as-array
Add support to placeholders as array
2 parents 0c86fd2 + 8f58bb9 commit fb24f91

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/Visitor/Php/Symfony/FormTypePlaceholder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ public function enterNode(Node $node): ?Node
9494
} elseif ($placeholderNode->value instanceof Node\Expr\ConstFetch && 'false' === $placeholderNode->value->name->toString()) {
9595
// 'placeholder' => false,
9696
// Do noting
97+
} elseif ($placeholderNode->value instanceof Node\Expr\Array_) {
98+
foreach ($placeholderNode->value->items as $placeholderNode) {
99+
$line = $placeholderNode->value->getAttribute('startLine');
100+
if (null !== $location = $this->getLocation($placeholderNode->value->value, $line, $placeholderNode, ['domain' => $domain])) {
101+
$this->lateCollect($location);
102+
}
103+
}
97104
} else {
98105
$this->addError($placeholderNode, 'Form placeholder is not a scalar string');
99106
}

tests/Functional/Visitor/Php/Symfony/FormTypePlaceholderTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ public function testExtract()
2626
$collection = $this->getSourceLocations(new FormTypePlaceholder(),
2727
Resources\Php\Symfony\PlaceholderFormType::class);
2828

29-
$this->assertCount(3, $collection);
29+
$this->assertCount(6, $collection);
3030
$this->assertEquals('form.placeholder.text', $collection->get(0)->getMessage());
3131
$this->assertEquals('form.placeholder.text.but.no.label', $collection->get(1)->getMessage());
3232
$this->assertEquals('form.choice_placeholder', $collection->get(2)->getMessage());
33+
$this->assertEquals('form.date_placeholder.year', $collection->get(3)->getMessage());
34+
$this->assertEquals('form.date_placeholder.month', $collection->get(4)->getMessage());
35+
$this->assertEquals('form.date_placeholder.day', $collection->get(5)->getMessage());
3336
}
3437

3538
public function testExtractError()

tests/Resources/Php/Symfony/PlaceholderFormType.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ public function buildForm(FormBuilderInterface $builder, array $options)
1818
'label' => false,
1919
'attr' => array('placeholder' => 'form.placeholder.text.but.no.label')
2020
))
21-
->add('field_placeholder', 'choice', array(
21+
->add('choice_field_placeholder', 'choice', array(
2222
'placeholder' => 'form.choice_placeholder'
2323
))
24+
->add('date_field_placeholder', 'date', array(
25+
'placeholder' => [
26+
'year' => 'form.date_placeholder.year',
27+
'month' => 'form.date_placeholder.month',
28+
'day' => 'form.date_placeholder.day'
29+
],
30+
))
2431
;
2532
}
2633
}

0 commit comments

Comments
 (0)