Commit e92465b5 authored by alexpott's avatar alexpott
Browse files

Issue #2329753 by lauriii, davidhernandez, LewisNyman, nathandao: Move html...

Issue #2329753 by lauriii, davidhernandez, LewisNyman, nathandao: Move html classes from preprocess to templates
parent 7b83db3c
......@@ -1338,23 +1338,11 @@ function template_preprocess_html(&$variables) {
$variables['attributes']['class'][] = 'db-offline';
}
// Add a class that tells us whether the page is viewed by an authenticated
// user.
if ($variables['logged_in']) {
$variables['attributes']['class'][] = 'user-logged-in';
}
// Add a class that tells us what path the page is located make it possible
// to theme the page depending on the current path (e.g. node, admin, user,
// etc.) as well as more specific data like path-frontpage.
// Add a variable for the root path. This can be used to create a class and
// theme the page depending on the current path (e.g. node, admin, user) as
// well as more specific data like path-frontpage.
$path = \Drupal::request()->getPathInfo();
if (drupal_is_front_page()) {
$variables['attributes']['class'][] = 'path-frontpage';
}
else {
$segment = explode('/', $path);
$variables['attributes']['class'][] = 'path-' . Html::getClass($segment[1]);
}
$variables['root_path'] = explode('/', $path)[1];
$site_config = \Drupal::config('system.site');
// Construct page title.
......
......@@ -494,7 +494,7 @@ function node_is_page(NodeInterface $node) {
function node_preprocess_html(&$variables) {
// If on an individual node page, add the node type to body classes.
if (($node = \Drupal::routeMatch()->getParameter('node')) && $node instanceof NodeInterface) {
$variables['attributes']['class'][] = Html::getClass('node--type-' . $node->getType());
$variables['node_type'] = $node->getType();
}
}
......
......@@ -4,6 +4,9 @@
* Default theme implementation for the basic structure of a single Drupal page.
*
* Variables:
* - logged_in: A flag indicating if user is logged in.
* - root_path: The root path of the current page (e.g., node, admin, user).
* - node_type: The content type for the current node, if the page is a node.
* - css: A list of CSS files for the current page.
* - head: Markup for the HEAD element (including meta tags, keyword tags, and
* so on).
......@@ -26,6 +29,13 @@
* @ingroup themeable
*/
#}
{%
set body_classes = [
logged_in ? 'user-logged-in',
not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class,
node_type ? 'node--type-' ~ node_type|clean_class,
]
%}
<!DOCTYPE html>
<html{{ html_attributes }}>
<head>
......@@ -34,7 +44,7 @@
{{ styles }}
{{ scripts }}
</head>
<body{{ attributes }}>
<body{{ attributes.addClass(body_classes) }}>
<a href="#main-content" class="visually-hidden focusable skip-link">
{{ 'Skip to main content'|t }}
</a>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment