protected function EntityReferenceFormatterTest::buildRenderArray in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php \Drupal\field\Tests\EntityReference\EntityReferenceFormatterTest::buildRenderArray()
Sets field values and returns a render array as built by \Drupal\Core\Field\FieldItemListInterface::view().
Parameters
\Drupal\Core\Entity\EntityInterface[] $referenced_entities: An array of entity objects that will be referenced.
string $formatter: The formatted plugin that will be used for building the render array.
array $formatter_options: Settings specific to the formatter. Defaults to the formatter's default settings.
Return value
array A render array.
3 calls to EntityReferenceFormatterTest::buildRenderArray()
- EntityReferenceFormatterTest::testEntityFormatter in core/
modules/ field/ src/ Tests/ EntityReference/ EntityReferenceFormatterTest.php - Tests the entity formatter.
- EntityReferenceFormatterTest::testIdFormatter in core/
modules/ field/ src/ Tests/ EntityReference/ EntityReferenceFormatterTest.php - Tests the ID formatter.
- EntityReferenceFormatterTest::testLabelFormatter in core/
modules/ field/ src/ Tests/ EntityReference/ EntityReferenceFormatterTest.php - Tests the label formatter.
File
- core/
modules/ field/ src/ Tests/ EntityReference/ EntityReferenceFormatterTest.php, line 286 - Contains \Drupal\field\Tests\EntityReference\EntityReferenceFormatterTest.
Class
- EntityReferenceFormatterTest
- Tests the formatters functionality.
Namespace
Drupal\field\Tests\EntityReferenceCode
protected function buildRenderArray(array $referenced_entities, $formatter, $formatter_options = array()) {
// Create the entity that will have the entity reference field.
$referencing_entity = entity_create($this->entityType, array(
'name' => $this
->randomMachineName(),
));
$items = $referencing_entity
->get($this->fieldName);
// Assign the referenced entities.
foreach ($referenced_entities as $referenced_entity) {
$items[] = [
'entity' => $referenced_entity,
];
}
// Build the renderable array for the field.
return $items
->view(array(
'type' => $formatter,
'settings' => $formatter_options,
));
}