Fix for Pattern Lab Pattern Viewer Not Displaying Namespaced Lineage Twig Paths #105
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1st pass at updating how PL template lineage matches are handled, even if the regex for a lineage matches up.
Addresses an annoying issue that's been going on for quite a long time now where the PL pattern viewer can't / won't correctly display the matched lineages of Twig partials when the @ namespace full path is used (vs the shorthand PL path syntax).
For example, given the following lineageMatch config in my config.yml file (separate PR?):
lineageMatch: '{%([ ]+)?(?:include|extends|embed)( |\()["\']([\/.@A-Za-z0-9-_]+)["\']([ A-Za-z0-9-&\}_\n\{":\',\/. \[\]]+)%}'
PL correctly picks up the pattern lineage in my code, even if I'm using a longhand / Twig namespaced path in my code (which is currently required for PL / Drupal to speak the same language, path-wise):
{% include "@atoms/typography/headings/h1.twig" with {
heading: {
text: "My Awesome Heading"
}
} %}
In my testing, I can confirm that this include correctly gets picked up when the $foundLineages array gets defined, however it seems to fail afterward due to the lineage path / string not being formatted in the compact shorthand format PL expects.
Basically, this PR works around this by doing some clunky PHP regex / string cleanup on the matched lineage path so it ends up matching what PL expects (feedback welcomed and appreciated)!