Change record status: 
Project: 
Introduced in branch: 
8.1.x
Introduced in version: 
8.1.0-beta1
Description: 

Wherever the targeted file is known to share the same module directory with the calling code (and whose relative position will not change dynamically), don't use drupal_get_path() or ExtensionList::getPath(). Use the __DIR__ constant to build the path to the referred file/directory.

Impacts: 
Module developers
Themers
Site templates, recipes and distribution developers

Comments

jelle_s’s picture

Do NOT use __DIR__ when overriding a path to a template in hook_theme_registry_alter. Since the Twig loader uses the relative path (relative to the Drupal root) of templates as cache key, and __DIR__ evaluates to an absolute path, you'll get an error like

Twig\Error\LoaderError: Template "[absolute path to template]" is not defined. in Twig\Loader\ChainLoader->getCacheKey() 

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."