|
7 | 7 | import fr.adrienbrault.idea.symfony2plugin.extension.TwigNamespaceExtensionParameter;
|
8 | 8 | import org.jetbrains.annotations.NotNull;
|
9 | 9 |
|
| 10 | +import java.util.ArrayList; |
10 | 11 | import java.util.Arrays;
|
11 | 12 | import java.util.Collection;
|
12 |
| -import java.util.Collections; |
| 13 | +import java.util.List; |
13 | 14 |
|
14 | 15 | /**
|
15 | 16 | * app/Resources/views/foo.html.twig => :foo.html.twig
|
16 | 17 | * app/Resources/views/foo.html.twig => foo.html.twig
|
17 | 18 | *
|
| 19 | + * /templates/foo.html.twig => foo.html.twig |
| 20 | + * /templates/foo.html.twig => :foo.html.twig |
| 21 | + * |
18 | 22 | * @author Daniel Espendiller <[email protected]>
|
19 | 23 | */
|
20 | 24 | public class GlobalAppTwigNamespaceExtension implements TwigNamespaceExtension {
|
21 | 25 | @NotNull
|
22 | 26 | @Override
|
23 | 27 | public Collection<TwigPath> getNamespaces(@NotNull TwigNamespaceExtensionParameter parameter) {
|
24 |
| - String appDirectoryName = Settings.getInstance(parameter.getProject()).directoryToApp + "/Resources/views"; |
25 | 28 | VirtualFile baseDir = parameter.getProject().getBaseDir();
|
26 | 29 |
|
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<>(); |
33 | 31 |
|
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"} |
37 | 35 | );
|
| 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; |
38 | 51 | }
|
39 | 52 | }
|
0 commit comments