Skip to content
Snippets Groups Projects

Issue #3143678by ckng: Allow node/entity to display title/label field as normal

3 unresolved threads
+ 8
15
@@ -6,6 +6,8 @@
*/
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\node\Entity\Node;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Form\FormStateInterface;
/**
@@ -139,20 +141,11 @@ function manage_display_form_system_theme_settings_alter(&$form, FormStateInterf
}
/**
* Implements template_preprocess_node().
* Implements hook_ENTITY_TYPE_view() for node entities.
*/
function manage_display_preprocess_node(&$variables) {
$node = $variables['elements']['#node'];
// Add title markup to content array.
$display_view_mode = 'node.' . $node->getType() . '.' . $variables['view_mode'];
$display = \Drupal::entityTypeManager()->getStorage('entity_view_display')->load($display_view_mode);
if ($display) {
$title_field = $display->getComponent('title');
$variables['content']['title'] = [
'#markup' => $variables['elements']['#title'],
'#weight' => $title_field['weight'],
];
}
function manage_display_node_view(array &$build, Node $entity, EntityViewDisplayInterface $display, $view_mode) {
$build['title_field'] = $build['title'];
$title_field = $display->getComponent('title');
$build['title_field']['#weight'] = $title_field['weight'];
unset($build['title']);
}
Loading