1111import com .jetbrains .php .roots .PhpNamespaceCompositeProvider ;
1212import fr .adrienbrault .idea .symfony2plugin .Symfony2Icons ;
1313import fr .adrienbrault .idea .symfony2plugin .Symfony2ProjectComponent ;
14+ import fr .adrienbrault .idea .symfony2plugin .util .PhpElementsUtil ;
1415import fr .adrienbrault .idea .symfony2plugin .util .psi .PhpBundleFileFactory ;
1516import org .apache .commons .lang3 .StringUtils ;
1617import org .jetbrains .annotations .NotNull ;
1718
1819import javax .swing .*;
1920import java .util .HashMap ;
2021import java .util .List ;
22+ import java .util .Map ;
2123
2224/**
2325 * @author Daniel Espendiller <daniel@espendiller.net>
@@ -63,16 +65,19 @@ public void actionPerformed(@NotNull AnActionEvent event) {
6365 return ;
6466 }
6567
68+ // Detect available Twig attributes in the project
69+ String templateName = detectTemplate (project );
70+
6671 ApplicationManager .getApplication ().runWriteAction (() -> {
67- HashMap <String , String > hashMap = new HashMap <>() {{
72+ Map <String , String > hashMap = new HashMap <>() {{
6873 put ("class" , className );
6974 put ("namespace" , strings .get (0 ));
7075 }};
7176
7277 PsiElement commandAttributes = PhpBundleFileFactory .createFile (
7378 project ,
7479 directory .getVirtualFile (),
75- "twig_extension" ,
80+ templateName ,
7681 className ,
7782 hashMap
7883 );
@@ -81,6 +86,17 @@ public void actionPerformed(@NotNull AnActionEvent event) {
8186 });
8287 }
8388
89+ @ NotNull
90+ private static String detectTemplate (@ NotNull Project project ) {
91+ // If attributes are available, use the new attribute-based template
92+ if (PhpElementsUtil .getClassInterface (project , "\\ Twig\\ Attribute\\ AsTwigFunction" ) != null ) {
93+ return "twig_extension_function_attribute" ;
94+ }
95+
96+ // Default to traditional template
97+ return "twig_extension" ;
98+ }
99+
84100 public static class Shortcut extends NewTwigExtensionAction {
85101 @ Override
86102 public void update (@ NotNull AnActionEvent event ) {
0 commit comments