Skip to content

Commit 70994f1

Browse files
authored
Merge pull request #1525 from Haehnchen/feature/named-form
support form type extraction of FormFactoryInterface::createNamed inside Twig type resolving
2 parents 98e90c2 + 0f7a1f0 commit 70994f1

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/variable/resolver/FormFieldResolver.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,45 @@ public void resolve(Collection<TwigTypeContainer> targets, Collection<TwigTypeCo
8080
}
8181

8282
private static void attachFormFields(@Nullable MethodReference methodReference, @NotNull Collection<TwigTypeContainer> targets) {
83-
if(methodReference != null && PhpElementsUtil.isMethodReferenceInstanceOf(
83+
if (methodReference == null) {
84+
return;
85+
}
86+
87+
int index = -1;
88+
89+
if (PhpElementsUtil.isMethodReferenceInstanceOf(
8490
methodReference,
8591
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "createForm"),
8692
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "createForm"),
8793
new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "createForm"),
8894
new MethodMatcher.CallToSignature("\\Symfony\\Component\\Form\\FormFactoryInterface", "create")
8995
)) {
90-
PsiElement formType = PsiElementUtils.getMethodParameterPsiElementAt(methodReference, 0);
91-
if(formType != null) {
92-
PhpClass phpClass = FormUtil.getFormTypeClassOnParameter(formType);
96+
index = 0;
97+
} else if (PhpElementsUtil.isMethodReferenceInstanceOf(
98+
methodReference,
99+
new MethodMatcher.CallToSignature("\\Symfony\\Component\\Form\\FormFactoryInterface", "createNamed")
100+
)) {
101+
index = 1;
102+
}
93103

94-
if(phpClass == null) {
95-
return;
96-
}
104+
if (index < 0) {
105+
return;
106+
}
97107

98-
Method method = phpClass.findMethodByName("buildForm");
99-
if(method == null) {
100-
return;
101-
}
108+
PsiElement formType = PsiElementUtils.getMethodParameterPsiElementAt(methodReference, index);
109+
if(formType != null) {
110+
PhpClass phpClass = FormUtil.getFormTypeClassOnParameter(formType);
102111

103-
targets.addAll(getTwigTypeContainer(method, phpClass));
112+
if(phpClass == null) {
113+
return;
104114
}
115+
116+
Method method = phpClass.findMethodByName("buildForm");
117+
if(method == null) {
118+
return;
119+
}
120+
121+
targets.addAll(getTwigTypeContainer(method, phpClass));
105122
}
106123
}
107124

0 commit comments

Comments
 (0)