public function YamlFormSubmissionListBuilder::buildRowColumn in YAML Form 8
Build row column.
Parameters
array $column: Column settings.
\Drupal\Core\Entity\EntityInterface $entity: A form 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 YamlFormSubmissionListBuilder::buildRowColumn()
- YamlFormSubmissionListBuilder::buildRow in src/
YamlFormSubmissionListBuilder.php - Builds a row for an entity in the entity listing.
File
- src/
YamlFormSubmissionListBuilder.php, line 356
Class
- YamlFormSubmissionListBuilder
- Provides a list controller for yamlform submission entity.
Namespace
Drupal\yamlformCode
public function buildRowColumn(array $column, EntityInterface $entity) {
$is_raw = $column['format'] == 'raw';
$name = $column['name'];
switch ($name) {
case 'created':
case 'completed':
case 'changed':
return $is_raw ? $entity->created->value : \Drupal::service('date.formatter')
->format($entity->created->value);
case 'entity':
$source_entity = $entity
->getSourceEntity();
if (!$source_entity) {
return '';
}
return $is_raw ? $source_entity->getEntityTypeId . ':' . $source_entity
->id() : $source_entity
->toLink();
case 'langcode':
return $is_raw ? $entity->langcode->value : \Drupal::languageManager()
->getLanguage($entity->langcode->value)
->getName();
case 'notes':
$route_name = $this->requestHandler
->getRouteName($entity, $entity
->getSourceEntity(), 'yamlform_submission.notes_form');
$route_parameters = $this->requestHandler
->getRouteParameters($entity, $entity
->getSourceEntity());
$route_options = [
'query' => \Drupal::destination()
->getAsArray(),
];
$state = $entity
->get('notes')->value ? 'on' : 'off';
return [
'data' => [
'#type' => 'link',
'#title' => new FormattableMarkup('<span class="yamlform-icon yamlform-icon-notes yamlform-icon-notes--@state"></span>', [
'@state' => $state,
]),
'#url' => Url::fromRoute($route_name, $route_parameters, $route_options),
'#attributes' => YamlFormDialogHelper::getModalDialogAttributes(640),
],
'class' => [
'yamlform-results__icon',
],
];
case 'operations':
return [
'data' => $this
->buildOperations($entity),
];
case 'remote_addr':
return $entity
->getRemoteAddr();
case 'sid':
return $entity
->id();
case 'serial':
$route_name = $this->requestHandler
->getRouteName($entity, $this->sourceEntity, $this
->getSubmissionRouteName());
$route_parameters = $this->requestHandler
->getRouteParameters($entity, $this->sourceEntity);
$link_text = $entity
->serial() . ($entity
->isDraft() ? ' (' . $this
->t('draft') . ')' : '');
return Link::createFromRoute($link_text, $route_name, $route_parameters);
case 'sticky':
$route_name = 'entity.yamlform_submission.sticky_toggle';
$route_parameters = [
'yamlform' => $entity
->getYamlForm()
->id(),
'yamlform_submission' => $entity
->id(),
];
$state = $entity
->isSticky() ? 'on' : 'off';
return [
'data' => [
'#type' => 'link',
'#title' => new FormattableMarkup('<span class="yamlform-icon yamlform-icon-sticky yamlform-icon-sticky--@state"></span>', [
'@state' => $state,
]),
'#url' => Url::fromRoute($route_name, $route_parameters),
'#attributes' => [
'id' => 'yamlform-submission-' . $entity
->id() . '-sticky',
'class' => [
'use-ajax',
],
],
],
'class' => [
'yamlform-results__icon',
],
];
case 'uid':
return $is_raw ? $entity
->getOwner()
->id() : ($entity
->getOwner()
->getAccountName() ?: t('Anonymous'));
case 'uuid':
return $entity
->uuid();
case 'yamlform_id':
return $is_raw ? $entity
->getYamlForm()
->id() : $entity
->getYamlForm()
->toLink();
default:
if (strpos($name, 'element__') === 0) {
$data = $entity
->getData();
$element = $column['element'];
$key = $column['key'];
$value = isset($data[$key]) ? $data[$key] : '';
$options = $column;
/** @var \Drupal\yamlform\YamlFormElementInterface $element_handler */
$element_handler = $column['plugin'];
$html = $element_handler
->formatTableColumn($element, $value, $options);
return is_array($html) ? [
'data' => $html,
] : $html;
}
else {
return '';
}
}
}