Skip to content

Commit d679019

Browse files
committed
Add source/_patterns subdirectories to $filesystemLoaderPaths
1 parent 3e28821 commit d679019

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/PatternLab/PatternEngine/Twig/Loaders/PatternLoader.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,22 @@ public function __construct($options = array()) {
4646
if (is_dir($layoutsPath)) {
4747
$filesystemLoaderPaths[] = $layoutsPath;
4848
}
49-
49+
50+
// add source/_patterns subdirectories for Drupal theme template compatibility
51+
$patternSourceDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_patterns";
52+
$patternObjects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($patternSourceDir), \RecursiveIteratorIterator::SELF_FIRST);
53+
$patternObjects->setFlags(\FilesystemIterator::SKIP_DOTS);
54+
55+
// sort the returned objects
56+
$patternObjects = iterator_to_array($patternObjects);
57+
ksort($patternObjects);
58+
59+
foreach ($patternObjects as $name => $object) {
60+
if ($object->isDir()) {
61+
$filesystemLoaderPaths[] = $object->getPathname();
62+
}
63+
}
64+
5065
// add the paths to the filesystem loader if the paths existed
5166
if (count($filesystemLoaderPaths) > 0) {
5267
$loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths);

0 commit comments

Comments
 (0)