Skip to content

Commit 13e1285

Browse files
committed
add support for Symfony flex template path structure #922
1 parent 590340f commit 13e1285

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/fr/adrienbrault/idea/symfony2plugin/templating/path/GlobalAppTwigNamespaceExtension.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,46 @@
77
import fr.adrienbrault.idea.symfony2plugin.extension.TwigNamespaceExtensionParameter;
88
import org.jetbrains.annotations.NotNull;
99

10+
import java.util.ArrayList;
1011
import java.util.Arrays;
1112
import java.util.Collection;
12-
import java.util.Collections;
13+
import java.util.List;
1314

1415
/**
1516
* app/Resources/views/foo.html.twig => :foo.html.twig
1617
* app/Resources/views/foo.html.twig => foo.html.twig
1718
*
19+
* /templates/foo.html.twig => foo.html.twig
20+
* /templates/foo.html.twig => :foo.html.twig
21+
*
1822
* @author Daniel Espendiller <[email protected]>
1923
*/
2024
public class GlobalAppTwigNamespaceExtension implements TwigNamespaceExtension {
2125
@NotNull
2226
@Override
2327
public Collection<TwigPath> getNamespaces(@NotNull TwigNamespaceExtensionParameter parameter) {
24-
String appDirectoryName = Settings.getInstance(parameter.getProject()).directoryToApp + "/Resources/views";
2528
VirtualFile baseDir = parameter.getProject().getBaseDir();
2629

27-
VirtualFile globalDirectory = VfsUtil.findRelativeFile(baseDir, appDirectoryName.split("/"));
28-
if(globalDirectory == null) {
29-
return Collections.emptyList();
30-
}
31-
32-
String path = globalDirectory.getPath();
30+
Collection<TwigPath> paths = new ArrayList<>();
3331

34-
return Arrays.asList(
35-
new TwigPath(path, TwigPathIndex.MAIN, TwigPathIndex.NamespaceType.BUNDLE),
36-
new TwigPath(path, TwigPathIndex.MAIN, TwigPathIndex.NamespaceType.ADD_PATH)
32+
List<String[]> templatePaths = Arrays.asList(
33+
new String[]{Settings.getInstance(parameter.getProject()).directoryToApp, "Resources", "views"},
34+
new String[]{"templates"}
3735
);
36+
37+
for (String[] strings1 : templatePaths) {
38+
VirtualFile globalDirectory = VfsUtil.findRelativeFile(baseDir, strings1);
39+
40+
if(globalDirectory == null) {
41+
continue;
42+
}
43+
44+
String path = globalDirectory.getPath();
45+
46+
paths.add(new TwigPath(path, TwigPathIndex.MAIN, TwigPathIndex.NamespaceType.BUNDLE));
47+
paths.add(new TwigPath(path, TwigPathIndex.MAIN, TwigPathIndex.NamespaceType.ADD_PATH));
48+
}
49+
50+
return paths;
3851
}
3952
}

0 commit comments

Comments
 (0)