Calling drupal_find_theme_templates() in a theme directory with a field called node--banner-tab.haml

You get:
Array
(
[] => Array
(
[template] =>
[path] => sites/all/themes/cti/templates
[render element] => elements
[base hook] => node
)

)

Should get:
Array
(
[node__banner_tab] => Array
(
[template] => node--banner-tab
[path] => sites/all/themes/cti/templates
[render element] => elements
[base hook] => node
)
)

Due to drupal_scan_directory() using pathinfo() to get the basename of template files, files named something.tpl.php will be returned as something.tpl. This is handled correctly for standard templates (checks to see if there is an extraneous extension before stripping it), but for dynamic templates it assumes that it will have an extension and attempts to strip it. This massively breaks when you're using a theme engine that only uses one extension for templates (such as ".haml", as used by Peroxide).

I've attached a patch to fix the handling in all cases.

Comments

randomblast’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Patch (to be ported)
xjm’s picture

Status: Patch (to be ported) » Needs review

patch_commit_ad6b6cffcbbd.patch queued for re-testing.

oadaeh’s picture

I've recreated the patch for the current state of D8. The code seems fine, but I'm not entirely sure how to test that it does what is claims to do.

Status: Needs review » Needs work

The last submitted patch, 3: theme-system-file-extension-removal-1120798-3.patch, failed testing.

oadaeh’s picture

Issue summary: View changes
Status: Needs work » Postponed (maintainer needs more info)

Considering this is now nearly three years old, is this still a valid issue?
Looking at that function now, it no longer resembles what the patch was against and processes the files in a different way:

        foreach ($matches as $match) {
          $file = $match;
          // Remove the extension from the filename.
          $file = str_replace($extension, '', $file);
          // Put the underscores back in for the hook name and register this
          // pattern.
          $arg_name = isset($info['variables']) ? 'variables' : 'render element';
          $implementations[strtr($file, '-', '_')] = array(
            'template' => $file,
            'path' => dirname($files[$match]->uri),
            $arg_name => $info[$arg_name],
            'base hook' => $hook,
          );
        }
star-szr’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Postponed (maintainer needs more info) » Active
Issue tags: +Needs tests

I can confirm this was fixed in D8 by #1900458-13: Use .html.twig instead of .twig file extension, in particular see the interdiff there.

A similar approach should probably work fine for D7 because drupal_find_theme_templates() still gets an extension passed in. However, this change could be slightly risky. Changing the version accordingly so this can be considered, and bugs need tests.

Thanks for bumping this @oadaeh :)

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.