fede-green
8/21/2017 - 8:35 AM

Module implementing custom template suggestions

Module implementing custom template suggestions altering an already existing hook.

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function MYMODULE_theme_suggestions_HOOK_alter(array &$suggestions, array $variables) {
  array_unshift($suggestions, 'ADD_MY_MODULE_SUGGESTION');
}
/**
 * Implements hook_theme_registry_alter().
 */
function MYMODULE_theme_registry_alter(&$theme_registry) {
  // Adding this modules's templates to the bunch.
  // Html.html.twig
  $theme_registry['ADD_MY_MODULE_SUGGESTION'] = $theme_registry['html'];
  $theme_registry['ADD_MY_MODULE_SUGGESTION']['path'] = drupal_get_path('module', 'MYMODULE') . '/templates';
  $theme_registry['ADD_MY_MODULE_SUGGESTION']['template'] = 'MY--TEMPLATE';
}