Skip to content

Commit c76b119

Browse files
committed
Add support for Twig namespace includes
1 parent aac3eb4 commit c76b119

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/aleksip/DataTransformPlugin/Twig/PatternDataNodeVisitor.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ protected function doLeaveNode(\Twig_Node $node, \Twig_Environment $env)
2323
if ($node instanceof \Twig_Node_Include) {
2424
if ($node->hasNode('expr') && $node->getNode('expr')->hasAttribute('value')) {
2525
$patternStoreKey = $node->getNode('expr')->getAttribute('value');
26+
27+
// Handle Twig namespace includes
28+
if ($patternStoreKey[0] == '@') {
29+
$patternStoreKey = ltrim($patternStoreKey, '@');
30+
$lineageParts = explode('/', $patternStoreKey);
31+
$length = count($lineageParts);
32+
$patternType = $lineageParts[0];
33+
34+
$patternName = $lineageParts[$length - 1];
35+
$patternName = ltrim($patternName, '_');
36+
$patternName = preg_replace('/^[0-9\-]+/', '', $patternName);
37+
38+
$patternNameStripped = explode('.twig', $patternName);
39+
40+
if (count($patternNameStripped) > 1) {
41+
$patternName = $patternNameStripped[0];
42+
}
43+
$patternName = str_replace('.', '-', $patternName);
44+
$patternStoreKey = $patternType . "-" . $patternName;
45+
}
46+
2647
$data = $this->dt->getProcessedPatternSpecificData($patternStoreKey);
2748
if ($node instanceof \Twig_Node_Embed) {
2849
$dataNode = new PatternDataEmbedNode($node, $data);

0 commit comments

Comments
 (0)