function tb_megamenu_find_hook_templates in The Better Mega Menu 7
1 call to tb_megamenu_find_hook_templates()
- tb_megamenu_theme_registry_alter in ./tb_megamenu.module
- Implements hook_theme_registry_alter().
File
- ./tb_megamenu.functions.inc, line 534
Code
function tb_megamenu_find_hook_templates($cache, $path) {
$templates = array();
$regex = '/\\.tpl\\.php$/';
$files = drupal_system_listing($regex, $path, 'name', 0);
if (isset($files['tb-megamenu-submenu--default.tpl'])) {
unset($files['tb-megamenu-submenu--default.tpl']);
}
foreach ($files as $template => $file) {
if (($pos = strpos($template, '.')) !== FALSE) {
$template = substr($template, 0, $pos);
}
$hook = strtr($template, '-', '_');
if (isset($cache[$hook])) {
$templates[$hook] = array(
'template' => $template,
'path' => dirname($file->uri),
'includes' => isset($cache[$hook]['includes']) ? $cache[$hook]['includes'] : NULL,
);
}
if (isset($cache[$hook]['pattern'])) {
$templates[$hook]['pattern'] = $cache[$hook]['pattern'];
}
}
$patterns = array_keys($files);
foreach ($cache as $hook => $info) {
if (!empty($info['pattern'])) {
$pattern = strtr($info['pattern'], '_', '-');
$matches = preg_grep('/^' . $pattern . '/', $patterns);
if ($matches) {
foreach ($matches as $match) {
$file = substr($match, 0, strpos($match, '.'));
$templates[strtr($file, '-', '_')] = array(
'template' => $file,
'path' => dirname($files[$match]->uri),
'variables' => isset($info['variables']) ? $info['variables'] : NULL,
'render element' => isset($info['render element']) ? $info['render element'] : NULL,
'base hook' => $hook,
'includes' => isset($info['includes']) ? $info['includes'] : NULL,
);
}
}
}
}
return $templates;
}