MDL-50346 core: Allow sub-directories in template names
This commit is contained in:
@@ -99,13 +99,34 @@ class api {
|
||||
|
||||
foreach ($templatedirs as $templatecomponent => $dirs) {
|
||||
foreach ($dirs as $dir) {
|
||||
if (!is_dir($dir) || !is_readable($dir)) {
|
||||
continue;
|
||||
}
|
||||
$dir = realpath($dir);
|
||||
|
||||
// List it.
|
||||
$files = glob($dir . '/*.mustache');
|
||||
$directory = new \RecursiveDirectoryIterator($dir);
|
||||
$files = new \RecursiveIteratorIterator($directory);
|
||||
|
||||
foreach ($files as $file) {
|
||||
$templatename = basename($file, '.mustache');
|
||||
if ($search == '' || strpos($templatename, $search) !== false) {
|
||||
$results[$templatecomponent . '/' . $templatename] = 1;
|
||||
if (!$file->isFile()) {
|
||||
continue;
|
||||
}
|
||||
$filename = substr($file->getRealpath(), strlen($dir) + 1);
|
||||
if (strpos($templatecomponent, 'theme_') === 0) {
|
||||
if (strpos($filename, '/') !== false && strpos($filename, 'local/') !== 0) {
|
||||
// Skip any template in a sub-directory of a theme which is not in a local directory.
|
||||
// These are theme overrides of core templates.
|
||||
// Note: There is a rare edge case where a theme may override a template and then have additional
|
||||
// dependant templates and these will not be shown.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$templatename = str_replace('.mustache', '', $filename);
|
||||
$componenttemplatename = "{$templatecomponent}/{$templatename}";
|
||||
|
||||
if ($search == '' || strpos($componenttemplatename, $search) !== false) {
|
||||
$results[$componenttemplatename] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,5 +173,4 @@ class api {
|
||||
return $templatestr;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user