public function MultipleItemsFieldWithCacheDependencyTest::viewElements in Extra Field 8
Same name and namespace in other branches
- 8.2 tests/extra_field_test/src/Plugin/ExtraField/Display/MultipleItemsFieldWithCacheDependencyTest.php \Drupal\extra_field_test\Plugin\ExtraField\Display\MultipleItemsFieldWithCacheDependencyTest::viewElements()
Returns the renderable array of the field item(s).
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The field's host entity.
Return value
array A renderable array of field elements. If this contains children, the field output will be rendered as a multiple value field with each child as a field item.
Overrides ExtraFieldDisplayFormattedInterface::viewElements
File
- tests/
extra_field_test/ src/ Plugin/ ExtraField/ Display/ MultipleItemsFieldWithCacheDependencyTest.php, line 79
Class
- MultipleItemsFieldWithCacheDependencyTest
- Extra field Display for a field with multiple items output.
Namespace
Drupal\extra_field_test\Plugin\ExtraField\DisplayCode
public function viewElements(ContentEntityInterface $entity) {
$build = [];
$another_node_type_nodes = $this->entityTypeManager
->getStorage('node')
->loadByProperties([
'type' => 'another_node_type',
]);
foreach ($another_node_type_nodes as $another_node) {
$build[] = [
'#markup' => $another_node
->label(),
];
$this->renderer
->addCacheableDependency($build, $another_node);
}
return $build;
}