openy_socrates-1.0.2/modules/openy_theme_override/openy_theme_override.module
modules/openy_theme_override/openy_theme_override.module
<?php
/**
* @file
* Module file.
*/
/**
* Implements hook_theme_registry_alter().
*/
function openy_theme_override_theme_registry_alter(&$theme_registry) {
$regex = '/' . str_replace('.', '\\.', "html.twig") . '$/';
$overrides = \Drupal::service('file_system')->scanDirectory(\Drupal::service('extension.list.module')->getPath('openy_theme_override') . '/themes', $regex, ['nomask' => TRUE], 100);
$themes = scandir(\Drupal::service('extension.list.module')->getPath('openy_theme_override') . '/themes');
unset($themes[1]);
unset($themes[0]);
$themes = array_values($themes);
$themes_path = \Drupal::service('extension.list.module')->getPath('openy_theme_override') . '/themes';
foreach ($overrides as $override) {
$output = explode(".", $override->name);
$template = $output[0];
$path = substr($override->uri, 0,strlen($override->uri) - strlen($override->filename) - 1);
$theme_path = substr($override->uri, strlen($themes_path) + 1);
$theme_name = explode("/", $theme_path);
$theme_name = $theme_name[0];
$overridden[$theme_name][$template]['path'] = $path;
$overridden[$theme_name][$template]['theme'] = $theme_name;
}
foreach ($theme_registry as &$item) {
$theme_name = explode("/", $item['theme path']);
$theme_name = end($theme_name);
if (isset($overridden[$theme_name]) && !is_null($overridden[$theme_name]) && array_key_exists($item['template'], $overridden[$theme_name])) {
if ($item['type'] !== 'theme_engine') {
continue;
}
$item['path'] = $overridden[$theme_name][$item['template']]['path'];
$item['theme path'] = $overridden[$theme_name][$item['template']]['path'];
}
}
}
