html_titles-8.x-1.x-dev/html_titles.module
html_titles.module
<?php
/**
* @file
* Contains hooks of html_titles module.
*/
use Drupal\Core\Render\Markup;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_node_presave().
*/
function html_titles_node_presave(EntityInterface $node) {
$s = Markup::create($node->getTitle());
$node->setTitle($s);
}
/**
* Implements hook_theme_registry_alter().
*/
function html_titles_theme_registry_alter(&$theme_registry) {
$theme_registry['field__node__title']['path'] = \Drupal::service('extension.list.module')->getPath('html_titles'). '/templates';
}
/**
* Implements hook_preprocess_field().
*/
function html_titles_preprocess_field(&$variables) {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node && !empty($variables['element']['#object']->title)) {
$s = Markup::create($variables['element']['#object']->label());
$variables['tit_h'] = $s;
}
}
/**
* Implements hook_preprocess_block().
*/
function html_titles_preprocess_block(&$variables) {
$variables['label'] = Markup::create($variables['label']);
}
/**
* Implements hook_preprocess_page_title().
*/
function html_titles_preprocess_page_title(&$variables) {
$current_path = \Drupal::service('path.current')->getPath();
if (strpos($current_path, 'term') !== FALSE && is_array($variables['title'])) {
if (array_key_exists('#markup', $variables['title'])) {
$variables['title']['#markup'] = Markup::create(htmlspecialchars_decode($variables['title']['#markup']));
}
}
}
