Skip to content

Instantly share code, notes, and snippets.

@calvez
Last active February 7, 2019 14:09
Show Gist options
  • Save calvez/b0d20a8d59b307c938651c8a49724115 to your computer and use it in GitHub Desktop.
Save calvez/b0d20a8d59b307c938651c8a49724115 to your computer and use it in GitHub Desktop.
drupal theme suggestions
<?php
/**
* Implements hook_theme_suggestions_HOOK() for contact form suggestion.
*/
function THEMENAME_theme_suggestions_form_alter(array &$suggestions, array $variables) {
$suggestions[] = 'form__' . $variables['element']['#form_id'];
}
<?php
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function magnetbank_theme_suggestions_page_alter(array &$suggestions, array $variables) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
if(is_numeric($node)) {
$node = \Drupal\node\Entity\Node::load($node);
}
if($node instanceof \Drupal\node\NodeInterface) {
array_splice($suggestions, 1, 0, 'page__' . $node->bundle());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment