Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I used Node title field block that from Layout builder, but this module not have support the field block, so I did some work on it.
I add a function preprocess hook for field--node--title twig.Get twig data before render it,get content and use decodeToMarkup function to decode html tag.
/**
* Implements hook_preprocess_HOOK
*/
function html_title_preprocess_field__node__title(&$vars) {
if ($vars && !empty($vars['field_name']) && $vars['field_name'] == 'title' && $vars['entity_type'] == 'node') {
if (is_array($vars['items']) && !empty($vars['items'])) {
foreach($vars['items'] as $key => $value) {
$item_text = $vars['items'][$key]['content']['#context']['value'];
$vars['items'][$key]['content']['#context']['value'] = \Drupal::service('html_title.filter')->decodeToMarkup($item_text);
}
}
}
}
Comment | File | Size | Author |
---|---|---|---|
#4 | 3157350-4-test-only.patch | 1.79 KB | JeroenT |
#4 | 3157350-4.patch | 2.67 KB | JeroenT |
| |||
#2 | node_title-3157350-2.patch | 1.18 KB | zhaoyao@ciandt.com |
| |||
event_pic.png | 9.82 KB | zhaoyao@ciandt.com |
Comments
Comment #2
zhaoyao@ciandt.com CreditAttribution: zhaoyao@ciandt.com commentedAdded a hook for _preprocess_field__node__title in this module to handle node title before twig render
Comment #3
himanshu_sindhwani CreditAttribution: himanshu_sindhwani at Srijan | A Material+ Company for Drupal India Association commentedComment #4
JeroenTComment #7
JeroenTCommitted and pushed to 8.x-1.x. Thanks!