public function TourListBuilder::buildRow in Tour UI 8
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/
TourListBuilder.php, line 29
Class
- TourListBuilder
- Provides a listing of tours.
Namespace
Drupal\tour_uiCode
public function buildRow(EntityInterface $entity) {
$row['title'] = [
'data' => $entity
->label(),
'class' => [
'menu-label',
],
];
$row = parent::buildRow($entity);
$data['id'] = Html::escape($entity
->id());
$data['label'] = Html::escape($entity
->label());
// Include the routes this tour is used on.
$routes_name = [];
if ($routes = $entity
->getRoutes()) {
foreach ($routes as $route) {
$params_out = '';
if (isset($route['route_params'])) {
$params = $route['route_params'];
$formatted_params = array_reduce(array_keys($params), function ($carry, $key) use ($params) {
return $carry . ' ' . $key . ':' . htmlspecialchars($params[$key]);
}, '');
$params_out = ' with params: ' . trim($formatted_params);
}
$routes_name[] = $route['route_name'] . $params_out;
}
}
$data['routes'] = [
'data' => [
'#type' => 'inline_template',
'#template' => '<div class="tour-routes">{{ routes|safe_join("<br />") }}</div>',
'#context' => [
'routes' => $routes_name,
],
],
];
// Count the number of tips.
$data['tips'] = count($entity
->getTips());
$data['operations'] = $row['operations'];
// Wrap the whole row so that the entity ID is used as a class.
return [
'data' => $data,
'class' => [
$entity
->id(),
],
];
}