body_node_id_class.module in Body node ID class 8
Adds a node ID class to the <body> tag.
File
body_node_id_class.moduleView source
<?php
/**
* @file
* Adds a node ID class to the <body> tag.
*/
use Drupal\node\Entity\Node;
/**
* Implements hook_preprocess_html().
*/
function body_node_id_class_preprocess_html(&$variables) {
// Add node id to the body class.
$node = \Drupal::routeMatch()
->getParameter('node');
if ($node instanceof Node) {
$variables['attributes']['class'][] = 'page-node-' . $node
->id();
$variables['attributes']['class'][] = 'page-node-type-' . $node
->bundle();
}
else {
$variables['attributes']['class'][] = 'page-node-' . $node;
}
}
Functions
Name![]() |
Description |
---|---|
body_node_id_class_preprocess_html | Implements hook_preprocess_html(). |