Skip to content

Commit 2c338ee

Browse files
committed
Merge branch 'patterns-to-loaderpaths' of https://github.com/aleksip/patternengine-php-twig into hotfix-prs
2 parents 49f9b82 + d679019 commit 2c338ee

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
@@ -48,7 +48,22 @@ public function __construct($options = array()) {
4848
if (is_dir($layoutsPath)) {
4949
$filesystemLoaderPaths[] = $layoutsPath;
5050
}
51-
51+
52+
// add source/_patterns subdirectories for Drupal theme template compatibility
53+
$patternSourceDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_patterns";
54+
$patternObjects = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($patternSourceDir), \RecursiveIteratorIterator::SELF_FIRST);
55+
$patternObjects->setFlags(\FilesystemIterator::SKIP_DOTS);
56+
57+
// sort the returned objects
58+
$patternObjects = iterator_to_array($patternObjects);
59+
ksort($patternObjects);
60+
61+
foreach ($patternObjects as $name => $object) {
62+
if ($object->isDir()) {
63+
$filesystemLoaderPaths[] = $object->getPathname();
64+
}
65+
}
66+
5267
// add the paths to the filesystem loader if the paths existed
5368
if (count($filesystemLoaderPaths) > 0) {
5469
$loaders[] = new \Twig_Loader_Filesystem($filesystemLoaderPaths);

0 commit comments

Comments
 (0)