I have a content type "Campus", I would like to concat to the title "Campus name campus". So, there is a hook or something to alter the node getTitle() method in every display?
I've tested:
- preprocess_node
- preprocess_page
- views_pre_build
- views_pre_render
- entity_view_alter
- preprocess_field__title
- preprocess_page_title
preprocess_field example code:
function usc_theme_preprocess_field(&$variables) {
if (!empty($variables['element'])) {
$field = $variables['element'];
if ($field['#bundle'] === 'campus' && $field['#field_name'] === 'title') {
/** @var \Drupal\node\Entity\Node $entity */
$field[0]['#context']['value'] = 'popopo';
/** @var \Drupal\Core\Field\FieldItemList $list */
$list = $field['#items'];
$val = $list->getValue()[0]['value'];
$field['#items'] = $list->setValue('testttttt');
$variables['element'] = $field;
$entity = $variables['element']['#object'];
$entity->title = 'aaa';
$variables['element']['#object'] = $entity;
}
}
}
Thanks all for help.
getTitle
,label()
, etc methods.