public function WebformNodeReferencesListController::buildRow in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_node/src/Controller/WebformNodeReferencesListController.php \Drupal\webform_node\Controller\WebformNodeReferencesListController::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
- modules/
webform_node/ src/ Controller/ WebformNodeReferencesListController.php, line 167
Class
- WebformNodeReferencesListController
- Defines a controller for webform node references.
Namespace
Drupal\webform_node\ControllerCode
public function buildRow(EntityInterface $entity) {
$webform = $this->webform;
/** @var \Drupal\node\NodeInterface $entity */
$row['title']['data'] = [
'#type' => 'link',
'#title' => $entity
->label(),
'#url' => $entity
->toUrl(),
];
$row['type'] = node_get_type_label($entity);
if ($webform
->hasVariants()) {
$variant_element_keys = $webform
->getElementsVariant();
foreach ($variant_element_keys as $variant_element_key) {
$variants = [];
foreach ($this->fieldNames as $field_name) {
if (!$entity
->hasField($field_name)) {
continue;
}
$default_data = Yaml::decode($entity->{$field_name}->default_data);
if (empty($default_data[$variant_element_key])) {
continue;
}
$variant_instance_id = $default_data[$variant_element_key];
if ($webform
->getVariants()
->has($variant_instance_id)) {
$variant_plugin = $webform
->getVariant($variant_instance_id);
$variants[$default_data[$variant_element_key]] = $variant_plugin
->label();
}
}
$row['element__' . $variant_element_key] = [
'data' => implode('; ', $variants),
'class' => [
RESPONSIVE_PRIORITY_LOW,
],
];
}
}
$row['author']['data'] = [
'#theme' => 'username',
'#account' => $entity
->getOwner(),
];
$row['changed'] = $this->dateFormatter
->format($entity
->getChangedTime(), 'short');
$row['node_status'] = $entity
->isPublished() ? $this
->t('Published') : $this
->t('Not published');
$row['webform_status'] = $this
->getWebformStatus($entity);
$result_total = $this
->getSubmissionStorage()
->getTotal($this->webform, $entity);
$results_access = $entity
->access('submission_view_any');
$results_disabled = $this->webform
->isResultsDisabled();
if ($results_disabled || !$results_access) {
$row['results'] = $result_total;
}
else {
$route_parameters = [
'node' => $entity
->id(),
];
$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' => Url::fromRoute('entity.node.webform.results_submissions', $route_parameters),
],
];
}
$row['operations']['data'] = $this
->buildOperations($entity);
return $row + parent::buildRow($entity);
}