drupal_find_theme_templates() may be unreliable when using nested themes

Created on 12 April 2016, about 8 years ago
Updated 14 March 2023, over 1 year ago

This issue was encountered on a Drupal 6 installation, but the code suggests it might apply to Drupal 7 as well:

  1. drupal_find_theme_templates() calls drupal_system_listing(), using the filename to index the results.
  2. drupal_system_listing() in turn calls file_scan_directory() which is dependent on the order in which readdir() returns files and uses depth to determine wether a match should replace a previous match.
  3. readdir() returns files in the order in which they have been stored in the file system.

Given the following two files:

  • parent_theme/templates/global/page.tpl.php
  • parent_theme/subthemes/child_theme/page.tpl.php

, page.tpl.php would no longer get picked up for the parent theme after a backup was restored. Debugging revealed that file_scan_directory would consistently return the page.tpl.php file of the child theme.
In this scenario restoring the backup changed the storage order of the involved files, thus causing the bug.

🐛 Bug report
Status

Needs work

Version

10.1

Component
Theme 

Last updated about 18 hours ago

Created by

🇩🇪Germany ciss

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇱Israel jkdev

    7 years later, the issue still exist.

    Only this time this is in: \Drupal\Core\File\FileSystem::doScanDirectory at web/core/lib/Drupal/Core/File/FileSystem.php:707:

    if ($handle = @opendir($dir)) {
          while (FALSE !== ($filename = readdir($handle))) {
    

    Can we work on this, so that in ext4 filesystems, this will not mess up themes?

    More info about my situation are here: #3329810 🐛 Stable9 override the material_base templates Closed: works as designed , #3316641 (with full easy reproduce)

    Can we use scandir instead?

    (scandir(string $directory, int $sorting_order = SCANDIR_SORT_ASCENDING, ?resource $context = null): array|false)

Production build 0.69.0 2024