aleksip / plugin-data-transform

Data Transform Plugin for Pattern Lab PHP
GNU General Public License v2.0
34 stars 10 forks source link

Twig extensions loaded through PL 'twigPatternLoader.customize' are not loaded if 'include()' transformer is used #24

Closed gambry closed 5 years ago

gambry commented 5 years ago

I created this twig extension and provided an autoload for PL using the 'twigPatternLoader.customize'.

The extension is not loaded if the 'include()' data transformer is used. It looks like when 'include()' is used the twig renderer is loaded earlier then needed, which setTwig_Environment::extensionInitialized to TRUE when actually things may still be loaded later on.

I tried to dig in to give more details, but didn't have enough time.

I believe the best - probably even long term - solution is to set priority -99 on subscriber $this->addListener('twigPatternLoader.customize', 'addNodeVisitor');. In this way this loader is likely to be loaded as last one, letting other plugins adding or altering twig extensions.

gambry commented 5 years ago

I created this twig extension and provided an autoload for PL using the 'twigPatternLoader.customize'. I'm not sure if this is good practice though. The PL documentation doesn't describe what events are for.

However I've seen this practice on other PL plugins providing or altering twig extensions, so better to fix this package as first.

aleksip commented 5 years ago

Merged your PR, thanks!