Created
October 19, 2018 17:24
-
-
Save DanLaufer/2858bdf590fe649ea43903094a4e1947 to your computer and use it in GitHub Desktop.
Drupal 8 - Template Suggestions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//PAGE Suggestions | |
$suggestions[] = 'page__path_alias__' . formatPathAlias($path_alias); | |
//NODE Suggestions | |
$node = \Drupal::request()->attributes->get('node'); | |
if (!is_null($node)) { | |
$node_alias = \Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$node->id()); | |
$view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); | |
$suggestions[] = 'node__path_alias__' . formatPathAlias($path_alias) . '__' . $view_mode; | |
} | |
//BLOCK Suggestions | |
function mytheme_theme_suggestions_block_alter(array &$suggestions, array $variables) { | |
// Block suggestions for custom block bundles. | |
if (isset($variables['elements']['content']['#block_content'])) { | |
array_splice($suggestions, 1, 0, 'block__bundle__' . $variables['elements']['content']['#block_content']->bundle()); | |
} | |
} | |
//FORM Suggestions | |
function mytheme_theme_suggestions_form_alter(&$suggestions, array $variables, $hook) { | |
$suggestions[] = $hook . '__' . $variables['element']['#form_id']; | |
} | |
//INPUT Suggestions | |
$suggestions[] = $hook . '__' . $variables['element']['#form_id'] . '__' . $variables['element']['#type']; | |
//CONTAINER Suggestions | |
if (isset($variables['element']['#form_id'])) { | |
$suggestions[] = $hook . '__' . $variables['element']['#form_id']; | |
} | |
//FORM ELEMENT Suggestions | |
if (isset($variables['element']['#name']) && isListingPageFacet($variables['element']['#name'])) { | |
$suggestions[] = $hook . '__' . $variables['element']['#type'] . '__listing_page'; | |
} | |
$suggestions[] = $hook . '__' . $variables['element']['#type']; | |
//FIELDSET Suggestions | |
if (isset($variables['element']['#name']) && isListingPageFacet($variables['element']['#name'])) { | |
$suggestions[] = $hook . '__' . $variables['element']['#type'] . '__listing_page'; | |
} | |
//Better Exposed Filters (BEF) Suggestions | |
if (isset($variables['element']['#name']) && isListingPageFacet($variables['element']['#name'])) { | |
$suggestions[] = $hook . '__' . $variables['element']['#type'] . '__listing_page'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment