Recent Posts


Magento 2: Symlinks for Modules


Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

One of the things Magento 2.1 doesn’t bring to the table is the ability to symlink your modules and other components. It’s hard to tell if this is a deliberate omission, or just something that’s not a priority for the development team and keeps getting lost in the shuffle. If you checkout the Context section of this GitHub bug, you can see Magento’s template validation does still check the allow symlinks setting, but the immediately does another check that could never pass with a module available via a symlink outside the Magento system’s folder structure.

Maddening, but something we can at least work around. If we create a module that has a plugin for the MagentoFrameworkViewElementTemplateFileValidator class

pestle.phar generate_module Pulsestorm DisableTemplateValidation 0.0.1

pestle.phar generate_plugin_xml Pulsestorm_DisableTemplateValidation MagentoFrameworkViewElementTemplateFileValidator PulsestormDisableTemplateValidationPluginMagentoFrameworkViewElementTemplateFileValidator

php bin/magento module:enable Pulsestorm_DisableTemplateValidation

php bin/magento setup:upgrade

and then create an after plugin for the isValid method that always returns true.

#File: app/code/Pulsestorm/DisableTemplateValidation/Plugin/Magento/Framework/View/Element/Template/File/Validator.php
<?php namespace PulsestormDisableTemplateValidationPluginMagentoFrameworkViewElementTemplateFile;
class Validator
    public function afterIsValid($subject, $result)
        $result = true;
        return $result;

We should be all set.

This probably isn’t something you want to do in a production system – loading templates outside of the Magento root is one step in a multi-step attack vector on Magento systems, but for developers working locally this seems like an OK work-around until Magento decides what they’re going to do w/r/t symlinks.

Copyright © Alan Storm 1975 – 2023 All Rights Reserved

Originally Posted: 28th June 2016