protected function WebformTable::formatHtmlItem in Webform 8.5
Same name and namespace in other branches
- 6.x src/Plugin/WebformElement/WebformTable.php \Drupal\webform\Plugin\WebformElement\WebformTable::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/ WebformTable.php, line 138
Class
- WebformTable
- Provides a 'webform_table' element.
Namespace
Drupal\webform\Plugin\WebformElementCode
protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$format = $this
->getItemFormat($element);
switch ($format) {
case 'details':
case 'details-closed':
case 'fieldset':
$element['#type'] = 'container';
break;
case 'table':
default:
$this
->prepareTableHeader($element);
// Switch submission display back to a Drupal table.
$element['#type'] = 'table';
unset($element['#states']);
break;
}
// Build each individual table row.
foreach ($element as $row_key => $row_element) {
if (Element::child($row_key)) {
$row_element_plugin = $this->elementManager
->getElementInstance($row_element);
$element[$row_key] = $row_element_plugin
->buildHtml($row_element, $webform_submission, $options);
}
}
return $element;
}