@@ -53,6 +53,51 @@ public function run() {
5353
5454 foreach ($ foundLineages as $ lineage ) {
5555
56+ /**
57+ * Fix for Pattern Lab Lineages when using Twig Namespaces.
58+ * Converts the full file path to PL-friendly shorthand so
59+ * they are internally registered.
60+ *
61+ * 1. Only handle instances where we aren't or can't use the
62+ * shorthand PL path reference in templates, specifically
63+ * in Twig / D8 when we need to use Twig namespaces in
64+ * our template paths.
65+ * 2. Strip off the @ sign at the beginning of our $lineage string.
66+ * 3. Break apart the full lineage path based on any slashes that
67+ * may exist.
68+ * 4. Store the length of our broken up path for reference below
69+ * 5. Store the first part of the string up to the first slash "/"
70+ * 6. Now grab the last part of the pattern key, based on the length
71+ * of the path we previously exploded.
72+ * 7. Remove any "_" from pattern Name.
73+ * 8. Remove any potential prefixed numbers or number + dash
74+ * combos on our Pattern Name.
75+ * 9. Strip off the pattern path extension (.twig,
76+ * .mustache, etc) if it exists.
77+ * 10. If the pattern name parsed had an extension,
78+ * re-assign our Pattern Name to that.
79+ * 11. Finally, re-assign $lineage to the default PL pattern key.
80+ */
81+
82+ if ($ lineage [0 ] == '@ ' ) { /* [1] */
83+ $ lineage = ltrim ($ lineage , '@ ' ); /* [2] */
84+ $ lineageParts = explode ('/ ' , $ lineage ); /* [3] */
85+ $ length = count ($ lineageParts ); /* [4] */
86+ $ patternType = $ lineageParts [0 ]; /* [5] */
87+
88+ $ patternName = $ lineageParts [$ length - 1 ]; /* [6] */
89+ $ patternName = ltrim ($ patternName , '_ ' ); /* [7] */
90+ $ patternName = preg_replace ('/^[0-9\-]+/ ' , '' ,
91+ $ patternName ); /* [8] */
92+
93+ $ patternNameStripped = explode ('. ' . $ patternExtension , $ patternName ); /* [9] */
94+
95+ if (count ($ patternNameStripped ) > 1 ) { /* [10] */
96+ $ patternName = $ patternNameStripped [0 ];
97+ }
98+ $ lineage = $ patternType . "- " . $ patternName ; /* [11] */
99+ }
100+
56101 if (PatternData::getOption ($ lineage )) {
57102
58103 $ patternLineages [] = array ("lineagePattern " => $ lineage ,
0 commit comments