public function WebformSubmissionViewBuilder::buildTable in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformSubmissionViewBuilder.php \Drupal\webform\WebformSubmissionViewBuilder::buildTable()
Build table display from elements and submitted data.
Parameters
array $elements: A flattened array webform elements that have values.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
array $options:
- excluded_elements: An array of elements to be excluded.
- email: Format element to be send via email.
Return value
array A render array displaying the submitted values in a table.
Overrides WebformSubmissionViewBuilderInterface::buildTable
1 call to WebformSubmissionViewBuilder::buildTable()
- WebformSubmissionViewBuilder::buildComponents in src/
WebformSubmissionViewBuilder.php - Builds the component fields and properties of a set of entities.
File
- src/
WebformSubmissionViewBuilder.php, line 210
Class
- WebformSubmissionViewBuilder
- Render controller for webform submissions.
Namespace
Drupal\webformCode
public function buildTable(array $elements, WebformSubmissionInterface $webform_submission, array $options = []) {
$rows = [];
foreach ($elements as $key => $element) {
if (!$this
->isElementVisible($element, $webform_submission, $options)) {
continue;
}
/** @var \Drupal\webform\Plugin\WebformElementInterface $webform_element */
$webform_element = $this->elementManager
->getElementInstance($element);
// Replace tokens before building the element.
$webform_element
->replaceTokens($element, $webform_submission);
// Check if empty value is excluded.
if ($webform_element
->isEmptyExcluded($element, $options) && !$webform_element
->getValue($element, $webform_submission, $options)) {
continue;
}
$title = $element['#admin_title'] ?: $element['#title'] ?: '(' . $key . ')';
// Note: Not displaying an empty message since empty values just render
// an empty table cell.
$html = $webform_element
->formatHtml($element, $webform_submission, $options);
$rows[$key] = [
[
'header' => TRUE,
'data' => $title,
],
[
'data' => is_string($html) ? [
'#markup' => $html,
] : $html,
],
];
}
return [
'#type' => 'table',
'#rows' => $rows,
'#attributes' => [
'class' => [
'webform-submission-table',
],
],
];
}