function NodeViewBuilder::buildComponents
Same name in other branches
- 9 core/modules/node/src/NodeViewBuilder.php \Drupal\node\NodeViewBuilder::buildComponents()
- 8.9.x core/modules/node/src/NodeViewBuilder.php \Drupal\node\NodeViewBuilder::buildComponents()
- 11.x core/modules/node/src/NodeViewBuilder.php \Drupal\node\NodeViewBuilder::buildComponents()
Overrides EntityViewBuilder::buildComponents
File
-
core/
modules/ node/ src/ NodeViewBuilder.php, line 18
Class
- NodeViewBuilder
- View builder handler for nodes.
Namespace
Drupal\nodeCode
public function buildComponents(array &$build, array $entities, array $displays, $view_mode) {
/** @var \Drupal\node\NodeInterface[] $entities */
if (empty($entities)) {
return;
}
parent::buildComponents($build, $entities, $displays, $view_mode);
foreach ($entities as $id => $entity) {
$bundle = $entity->bundle();
$display = $displays[$bundle];
if ($display->getComponent('links')) {
$build[$id]['links'] = [
'#lazy_builder' => [
static::class . '::renderLinks',
[
$entity->id(),
$view_mode,
$entity->language()
->getId(),
!empty($entity->in_preview),
$entity->isDefaultRevision() ? NULL : $entity->getLoadedRevisionId(),
],
],
];
}
// Add Language field text element to node render array.
if ($display->getComponent('langcode')) {
$build[$id]['langcode'] = [
'#type' => 'item',
'#title' => t('Language'),
'#markup' => $entity->language()
->getName(),
'#prefix' => '<div id="field-language-display">',
'#suffix' => '</div>',
];
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.