Skip to content
Snippets Groups Projects

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

3 unresolved threads
+ 27
0
@@ -5,6 +5,7 @@
* Make base fields such as 'title' available in "Manage Display".
*/
use Drupal\Component\Utility\NestedArray;
use Drupal\comment\CommentInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
@@ -380,3 +381,29 @@ function _manage_display_fix_comment_item(array &$item, string $name, CommentInt
}
}
}
/**
* Implements hook_ENTITY_TYPE_view().
*/
function manage_display_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
Please register or sign in to reply
if (isset($build['title']) && NULL !== $display->getComponent('title')) {
$build['_title'] = NestedArray::mergeDeep([], $build['title']);
    • Why would we merge with an empty array? We could just assign it, and it should be the same result. $build['_title'] = $build['title'];

Please register or sign in to reply
}
}
/**
* Implements hook_ENTITY_TYPE_view_alter().
*/
function manage_display_node_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
if (isset($build['_title']) && isset($build['#group_children']['title'])) {
Please register or sign in to reply
$field_group = $build['#group_children']['title'];
$build['#group_children']['_title'] = $field_group;
$build['#fieldgroups'][$field_group]->children[] = '_title';
$pos = array_search(
'title',
$build['#fieldgroups'][$field_group]->children,
TRUE
);
unset($build['#group_children']['title'], $build['#fieldgroups'][$field_group]->children[$pos]);
}
}
Loading