- 🇦🇫Afghanistan ab.shakir
#3 works for me while adding a pseudo field to field group via UI.
Hi,
I created a pseudo field to render the node title in various node view modes within field groups. This field called "mymdoule_title" is created by the following code:
/**
* Implements hook_entity_extra_field_info().
*/
function mymodule_entity_extra_field_info() {
$extra = array();
foreach (NodeType::loadMultiple() as $bundle) {
$extra['node'][$bundle->Id()]['display']['mymdoule_title'] = array(
'label' => t('Extra title'),
'description' => t('Display the title of the node e.g. in teaser'),
'weight' => 100,
'visible' => TRUE,
);
}
return $extra;
}
and then it is rendered with the following code:
/**
* Implements hook_ENTITY_TYPE_view for nodes
*
* - render our pseudo fields
*/
function mymodule_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
if ($display->getComponent('mymodule_title')) {
$build['igb_title'] = array(
'#type' => 'html_tag',
'#tag' => 'h2,
'#value' => $entity->label()
);
}
}
The rendering is working fine a) when this field is added to a view mode without being nested into a field group or b) when it is nested within a field group where another field is also placed which has a value. If there are other field within the field group but they are empty and therefore not rendered the pseudo field is not rendere either.
Steps to reproduce:
- add the above code to a custom module, rebuild cache
- go to any node type administration page and save a view mode with this new field directy in node/ without field group (for example admin/structure/types/manage/page/display)
- add a node of this type and view it -> you should see the node title a second time
- then go to view mode administration again and add this field to a field group
- when you view the node again the second title disappears
- then go to view mode administration again and add a second field to the field group which has a value for sure
- go to the node detail page again -> the second title is visible within the field group
I tried all this in a Drupal 7 installation with no problems - seems to be a new issue with Drupal 8.
Best,
Tobias
Closed: works as designed
Miscellaneous
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
#3 works for me while adding a pseudo field to field group via UI.