protected function EntityToTableRenderer::getPreparedRenderedEntities in Reference Table Formatter 8
Same name and namespace in other branches
- 2.0.x src/EntityToTableRenderer.php \Drupal\reference_table_formatter\EntityToTableRenderer::getPreparedRenderedEntities()
Prepare all of the given entities for rendering with applicable fields.
Parameters
string $type: The entity type of the given entities.
string $bundle: The bundle that the entities are composed of.
array $entities: An array of entities to put into the table.
array $settings: The settings array from the field formatter base containing keys:
- view_mode: The target view mode to render the field settings from.
- show_entity_label: If we should display the entity label.
- empty_cell_value: The value to show in empty cells.
Return value
array An array of entities with applicable fields prepared for rendering.
1 call to EntityToTableRenderer::getPreparedRenderedEntities()
- EntityToTableRenderer::getTable in src/
EntityToTableRenderer.php - Render the entities to a table.
File
- src/
EntityToTableRenderer.php, line 104
Class
- EntityToTableRenderer
- A service for turning entities into tables.
Namespace
Drupal\reference_table_formatterCode
protected function getPreparedRenderedEntities($type, $bundle, array $entities, array $settings) {
// Build, sort and filter the entity fields to ensure the weight is
// respected and we only show fields which are relevant or have been
// configured for the table.
$filtered_table_entities = [];
$display_renderer = $this
->getDisplayRenderer($type, $bundle, $settings['view_mode']);
foreach ($display_renderer
->buildMultiple($entities) as $table_entity) {
// Filter out fields which we don't want to render.
$filtered_entity = array_filter($table_entity, [
$this,
'fieldIsRenderableContent',
]);
// If we are showing the entity label, add it to the fields list.
if ($settings['show_entity_label']) {
$label_field_key = $this->entityManager
->getDefinition($type)
->getKey('label');
if ($label_field_key) {
$filtered_entity[$label_field_key] = $table_entity[$label_field_key];
}
}
// Sort the fields by weight.
uasort($filtered_entity, [
'\\Drupal\\Component\\Utility\\SortArray',
'sortByWeightProperty',
]);
$filtered_table_entities[] = $filtered_entity;
}
return $filtered_table_entities;
}