function exclude_node_title_preprocess_html in Exclude Node Title 8
Implements hook_preprocess_html().
File
- ./
exclude_node_title.module, line 40 - Primarily Drupal hooks and global API functions to exclude node titles.
Code
function exclude_node_title_preprocess_html(&$vars) {
if (!\Drupal::currentUser()
->hasPermission('use exclude node title')) {
return;
}
/** @var \Drupal\exclude_node_title\ExcludeNodeTitleManagerInterface $exclude_manager */
$exclude_manager = \Drupal::service('exclude_node_title.manager');
$route_match = \Drupal::routeMatch();
$route_name = $route_match
->getRouteName();
switch ($route_name) {
case 'entity.node.edit_form':
$node = $route_match
->getParameter('node');
$exclude_manager
->preprocessTitle($vars, $node, 'nodeform');
break;
case 'entity.node.canonical':
$node = $route_match
->getParameter('node');
if ($exclude_manager
->isTitleExcluded($node, 'full')) {
unset($vars['head_title']['title']);
// Add a class to pages with excluded node title.
$vars['attributes']['class'][] = 'exclude-node-title';
}
break;
}
}