public function WebformSubmissionListBuilder::buildRowColumn in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformSubmissionListBuilder.php \Drupal\webform\WebformSubmissionListBuilder::buildRowColumn()
Build row column.
Parameters
array $column: Column settings.
\Drupal\Core\Entity\EntityInterface $entity: A webform submission.
Return value
array|mixed The row column value or renderable array.
Throws
\Exception Throw exception if table row column is not found.
1 call to WebformSubmissionListBuilder::buildRowColumn()
- WebformSubmissionListBuilder::buildRow in src/
WebformSubmissionListBuilder.php - Builds a row for an entity in the entity listing.
File
- src/
WebformSubmissionListBuilder.php, line 854
Class
- WebformSubmissionListBuilder
- Provides a list controller for webform submission entity.
Namespace
Drupal\webformCode
public function buildRowColumn(array $column, EntityInterface $entity) {
/** @var \Drupal\webform\WebformSubmissionInterface $entity */
$is_raw = $column['format'] === 'raw';
$name = $column['name'];
switch ($name) {
case 'created':
case 'completed':
case 'changed':
return $is_raw ? $entity->{$name}->value : ($entity->{$name}->value ? $this->dateFormatter
->format($entity->{$name}->value) : '');
case 'entity':
$source_entity = $entity
->getSourceEntity(TRUE);
if (!$source_entity) {
return '';
}
return $is_raw ? $source_entity->getEntityTypeId . ':' . $source_entity
->id() : ($source_entity
->hasLinkTemplate('canonical') ? $source_entity
->toLink() : $source_entity
->label());
case 'langcode':
$langcode = $entity
->getLangcode();
if (!$langcode) {
return '';
}
if ($is_raw) {
return $langcode;
}
else {
$language = $this->languageManager
->getLanguage($langcode);
return $language ? $language
->getName() : $langcode;
}
case 'notes':
$notes_url = $this
->ensureDestination($this->requestHandler
->getUrl($entity, $entity
->getSourceEntity(TRUE), 'webform_submission.notes_form'));
$state = $entity
->get('notes')->value ? 'on' : 'off';
$t_args = [
'@label' => $entity
->label(),
];
$label = $entity
->get('notes')->value ? $this
->t('Edit @label notes', $t_args) : $this
->t('Add notes to @label', $t_args);
return [
'data' => [
'#type' => 'link',
'#title' => new FormattableMarkup('<span class="webform-icon webform-icon-notes webform-icon-notes--@state"></span><span class="visually-hidden">@label</span>', [
'@state' => $state,
'@label' => $label,
]),
'#url' => $notes_url,
'#attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NARROW),
],
'class' => [
'webform-results-table__icon',
],
];
case 'operations':
return [
'data' => $this
->buildOperations($entity),
'class' => [
'webform-dropbutton-wrapper',
],
];
case 'remote_addr':
return $entity
->getRemoteAddr();
case 'sid':
return $entity
->id();
case 'serial':
case 'label':
// Note: Use the submission's token URL which points to the
// submission's source URL with a secure token.
// @see \Drupal\webform\Entity\WebformSubmission::getTokenUrl
if ($entity
->isDraft()) {
$link_url = $entity
->getTokenUrl();
}
else {
$link_url = $this->requestHandler
->getUrl($entity, $entity
->getSourceEntity(TRUE), $this
->getSubmissionRouteName());
}
if ($name === 'serial') {
$link_text = $entity
->serial();
}
else {
$link_text = $entity
->label();
}
$link = Link::fromTextAndUrl($link_text, $link_url)
->toRenderable();
if ($name === 'serial') {
$link['#attributes']['title'] = $entity
->label();
$link['#attributes']['aria-label'] = $entity
->label();
}
if ($entity
->isDraft()) {
$link['#suffix'] = ' (' . $this
->t('draft') . ')';
}
return [
'data' => $link,
];
case 'in_draft':
return $entity
->isDraft() ? $this
->t('Yes') : $this
->t('No');
case 'sticky':
// @see \Drupal\webform\Controller\WebformSubmissionController::sticky
$route_name = 'entity.webform_submission.sticky_toggle';
$route_parameters = [
'webform' => $entity
->getWebform()
->id(),
'webform_submission' => $entity
->id(),
];
return [
'data' => [
'#type' => 'link',
'#title' => WebformSubmissionController::buildSticky($entity),
'#url' => Url::fromRoute($route_name, $route_parameters),
'#attributes' => [
'id' => 'webform-submission-' . $entity
->id() . '-sticky',
'class' => [
'use-ajax',
],
],
],
'class' => [
'webform-results-table__icon',
],
];
case 'locked':
// @see \Drupal\webform\Controller\WebformSubmissionController::locked
$route_name = 'entity.webform_submission.locked_toggle';
$route_parameters = [
'webform' => $entity
->getWebform()
->id(),
'webform_submission' => $entity
->id(),
];
return [
'data' => [
'#type' => 'link',
'#title' => WebformSubmissionController::buildLocked($entity),
'#url' => Url::fromRoute($route_name, $route_parameters),
'#attributes' => [
'id' => 'webform-submission-' . $entity
->id() . '-locked',
'class' => [
'use-ajax',
],
],
],
'class' => [
'webform-results-table__icon',
],
];
case 'uid':
return $is_raw ? $entity
->getOwner()
->id() : ($entity
->getOwner()
->getAccountName() ?: t('Anonymous'));
case 'uuid':
return $entity
->uuid();
case 'webform_id':
return $is_raw ? $entity
->getWebform()
->id() : $entity
->getWebform()
->toLink();
default:
if (strpos($name, 'element__') === 0) {
$element = $column['element'];
$options = $column;
/** @var \Drupal\webform\Plugin\WebformElementInterface $element_plugin */
$element_plugin = $column['plugin'];
$html = $element_plugin
->formatTableColumn($element, $entity, $options);
return is_array($html) ? [
'data' => $html,
] : $html;
}
else {
return '';
}
}
}