public function WebformEntityListBuilder::buildRow in Webform 8.5
Same name and namespace in other branches
- 6.x src/WebformEntityListBuilder.php \Drupal\webform\WebformEntityListBuilder::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/
WebformEntityListBuilder.php, line 282
Class
- WebformEntityListBuilder
- Defines a class to build a listing of webform entities.
Namespace
Drupal\webformCode
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\webform\WebformInterface */
// Title.
//
// ISSUE: Webforms that the current user can't access are not being hidden via the EntityQuery.
// WORK-AROUND: Don't link to the webform.
// See: Access control is not applied to config entity queries
// https://www.drupal.org/node/2636066
$row['title']['data']['title'] = [
'#markup' => $entity
->access('submission_page') ? $entity
->toLink()
->toString() : $entity
->label(),
];
if ($entity
->isTemplate()) {
$row['title']['data']['template'] = [
'#markup' => ' <b>(' . $this
->t('Template') . ')</b>',
];
}
// Description.
$row['description']['data'] = WebformHtmlEditor::checkMarkup($entity
->get('description'));
// Category.
$row['category']['data']['#markup'] = $entity
->get('category');
// Status.
$t_args = [
'@label' => $entity
->label(),
];
if ($entity
->isArchived()) {
$row['status']['data'] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => $this
->t('Archived'),
'#attributes' => [
'aria-label' => $this
->t('@label is archived', $t_args),
],
];
$row['status'] = $this
->t('Archived');
}
else {
switch ($entity
->get('status')) {
case WebformInterface::STATUS_OPEN:
$status = $this
->t('Open');
$aria_label = $this
->t('@label is open', $t_args);
break;
case WebformInterface::STATUS_CLOSED:
$status = $this
->t('Closed');
$aria_label = $this
->t('@label is closed', $t_args);
break;
case WebformInterface::STATUS_SCHEDULED:
$status = $this
->t('Scheduled (@state)', [
'@state' => $entity
->isOpen() ? $this
->t('Open') : $this
->t('Closed'),
]);
$aria_label = $this
->t('@label is scheduled and is @state', $t_args + [
'@state' => $entity
->isOpen() ? $this
->t('open') : $this
->t('closed'),
]);
break;
default:
return [];
}
if ($entity
->access('update')) {
$row['status']['data'] = $entity
->toLink($status, 'settings-form', [
'query' => $this
->getDestinationArray(),
])
->toRenderable() + [
'#attributes' => [
'aria-label' => $aria_label,
],
];
}
else {
$row['status']['data'] = [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => $status,
'#attributes' => [
'aria-label' => $aria_label,
],
];
}
}
// Owner.
$row['owner'] = ($owner = $entity
->getOwner()) ? $owner
->toLink() : '';
// Results.
$result_total = $this->storage
->getTotalNumberOfResults($entity
->id());
$results_disabled = $entity
->isResultsDisabled();
$results_access = $entity
->access('submission_view_any');
if ($results_disabled || !$results_access) {
$row['results'] = ($result_total ? $result_total : '') . ($result_total && $results_disabled ? ' ' : '') . ($results_disabled ? $this
->t('(Disabled)') : '');
}
else {
$row['results'] = [
'data' => [
'#type' => 'link',
'#title' => $result_total,
'#attributes' => [
'aria-label' => $this
->formatPlural($result_total, '@count result for @label', '@count results for @label', [
'@label' => $entity
->label(),
]),
],
'#url' => $entity
->toUrl('results-submissions'),
],
];
}
// Operations.
return $row + parent::buildRow($entity);
}