Use a multidimensional render array to keep the original title and prefix / suffix it

Created on 7 August 2024, 4 months ago
Updated 22 August 2024, 3 months ago

Problem/Motivation

Maybe we can use the recursive Drupal render array rendering logic to keep the original markup and simply add the prefix and suffix before / after as an array:

Original:

if (is_array($variables['title']) && !empty($variables['title']['#markup'])) {
  // Taxonomy terms use ['title']['#markup'] for their name:
  $variables['title']['#markup'] = $title_prefix . $variables['title']['#markup'] . $title_suffix;
}
else {
  $variables['title'] = node_title_ps_generate($title_prefix, $variables['title'], $title_suffix);
}

Idea to be proofed:

if (is_array($variables['title']) && !empty($variables['title']['#markup'])) {
  // Taxonomy terms use ['title']['#markup'] for their name:
  $originalTitle = $variables['title'];
  $variables['title'] = [];
  $variables['title'][] = ['#plain_text' => $prefix];
  $variables['title'][] = $originalTitle;
  $variables['title'][] = ['#plain_text' => $suffix];
}
else {
  $variables['title'] = node_title_ps_generate($title_prefix, $variables['title'], $title_suffix);
}

(If this works, we should unify this in node_title_ps_generate() perhaps?)

Steps to reproduce

Proposed resolution

Try if this works ;)

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024