Skip to content

Commit 2d92e42

Browse files
ChristopheNyholm
authored andcommitted
FormTypePlaceholder: fix issue with non array attr (function call) (#102)
* fix issue #101 * add issue_101 test * fix function signature
1 parent 517a8d2 commit 2d92e42

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Visitor/Php/Symfony/FormTypePlaceholder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function enterNode(Node $node)
4949
}
5050
} elseif ('placeholder' === $item->key->value) {
5151
$placeholderNode = $item;
52-
} elseif ('attr' === $item->key->value) {
52+
} elseif ('attr' === $item->key->value && $item->value instanceof Node\Expr\Array_) {
5353
foreach ($item->value->items as $attrValue) {
5454
if ('placeholder' === $attrValue->key->value) {
5555
$placeholderNode = $attrValue;

tests/Resources/Github/Issue_101.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Translation\Extractor\Tests\Resources\Php\Symfony;
4+
5+
class NotAnArrayAttrType
6+
{
7+
public function buildForm(FormBuilderInterface $builder, array $options)
8+
{
9+
$builder
10+
->add('field_with_function_as_attr_value', 'text', array(
11+
'attr' => $this->getAttrFunction()
12+
));
13+
}
14+
15+
public function getAttrFunction()
16+
{
17+
return array('maxlength' => 10);
18+
}
19+
}

0 commit comments

Comments
 (0)