public function RelationListBuilder::buildRow in Relation 8.2
Same name and namespace in other branches
- 8 src/RelationListBuilder.php \Drupal\relation\RelationListBuilder::buildRow()
Builds a row for an entity in the entity listing.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.
Return value
array A render array structure of fields for this entity.
Overrides EntityListBuilder::buildRow
See also
\Drupal\Core\Entity\EntityListBuilder::render()
File
- src/
RelationListBuilder.php, line 35
Class
- RelationListBuilder
- Provides a listing of relation types.
Namespace
Drupal\relationCode
public function buildRow(EntityInterface $entity) {
$row['label']['data'] = array(
'#type' => 'link',
'#title' => $entity
->label(),
) + $entity
->toUrl()
->toRenderArray();
$storage_handler = \Drupal::entityTypeManager()
->getStorage($entity
->getEntityType()
->getBundleEntityType());
$bundle = $storage_handler
->load($entity
->bundle());
$row['relation_type']['data'] = array(
'#type' => 'link',
'#title' => $bundle
->label(),
) + $bundle
->toUrl()
->toRenderArray();
$relation_entities = array();
$entity_count_total = 0;
$entity_count = 0;
foreach ($entity
->endpoints() as $type => $ids) {
$entity_count_total += count($ids);
$storage_handler = \Drupal::entityTypeManager()
->getStorage($type);
$entities = $storage_handler
->loadMultiple($ids);
foreach ($entities as $endpoint_entity) {
$entity_count++;
$relation_entities[] = array(
'#type' => 'link',
'#title' => $endpoint_entity
->label(),
) + $endpoint_entity
->toUrl()
->toRenderArray();
}
}
if ($entity_count_total != $entity_count) {
$relation_entities[] = \Drupal::translation()
->formatPlural($entity_count_total - $entity_count, 'Missing @count entity', 'Missing @count entities');
}
$row['endpoints']['data']['list'] = array(
'#theme' => 'item_list',
'#items' => $relation_entities,
);
return $row + parent::buildRow($entity);
}