protected function Table::formatHtmlItem in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/Table.php \Drupal\webform\Plugin\WebformElement\Table::formatHtmlItem()
Format an element's value as HTML.
Parameters
array $element: An element.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
array $options: An array of options.
Return value
array|string The element's value formatted as HTML or a render array.
Overrides WebformElementBase::formatHtmlItem
File
- src/
Plugin/ WebformElement/ Table.php, line 123
Class
- Table
- Provides a 'table' element.
Namespace
Drupal\webform\Plugin\WebformElementCode
protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$rows = [];
foreach ($element as $row_key => $row_element) {
if (WebformElementHelper::property($row_key)) {
continue;
}
$element[$row_key] = [];
foreach ($row_element as $column_key => $column_element) {
if (WebformElementHelper::property($column_key)) {
continue;
}
// Get column element plugin and get formatted HTML value.
$column_element_plugin = $this->elementManager
->getElementInstance($column_element);
$column_value = $column_element_plugin
->format('html', $column_element, $webform_submission, $options);
// If column value is empty see if we can use #markup.
if (empty($column_value) && isset($column_element['#markup'])) {
$column_value = $column_element['#markup'];
}
if (is_array($column_value)) {
$rows[$row_key][$column_key] = [
'data' => $column_value,
];
}
else {
$rows[$row_key][$column_key] = [
'data' => [
'#markup' => $column_value,
],
];
}
}
}
return $rows + $element;
}