protected function ContainerBase::formatHtmlItem in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/ContainerBase.php \Drupal\webform\Plugin\WebformElement\ContainerBase::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
2 calls to ContainerBase::formatHtmlItem()
- WebformCard::formatHtmlItem in modules/
webform_cards/ src/ Plugin/ WebformElement/ WebformCard.php - Format an element's value as HTML.
- WebformWizardPage::formatHtmlItem in src/
Plugin/ WebformElement/ WebformWizardPage.php - Format an element's value as HTML.
2 methods override ContainerBase::formatHtmlItem()
- WebformCard::formatHtmlItem in modules/
webform_cards/ src/ Plugin/ WebformElement/ WebformCard.php - Format an element's value as HTML.
- WebformWizardPage::formatHtmlItem in src/
Plugin/ WebformElement/ WebformWizardPage.php - Format an element's value as HTML.
File
- src/
Plugin/ WebformElement/ ContainerBase.php, line 119
Class
- ContainerBase
- Provides a base 'container' class.
Namespace
Drupal\webform\Plugin\WebformElementCode
protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
/** @var \Drupal\webform\WebformSubmissionViewBuilderInterface $view_builder */
$view_builder = $this->entityTypeManager
->getViewBuilder('webform_submission');
$children = $view_builder
->buildElements($element, $webform_submission, $options, 'html');
if (empty($children)) {
return [];
}
$format = $this
->getItemFormat($element);
// Emails can only display div containers with <h3>.
if (!empty($options['email'])) {
$format = 'header';
}
// Build format attributes.
$attributes = isset($element['#format_attributes']) ? $element['#format_attributes'] : [];
$attributes += [
'class' => [],
];
switch ($format) {
case 'details':
case 'details-closed':
$attributes['data-webform-element-id'] = $element['#webform_id'];
$attributes['class'][] = 'webform-container';
$attributes['class'][] = 'webform-container-type-details';
return [
'#type' => 'details',
'#title' => $element['#title'],
'#id' => $element['#webform_id'],
'#open' => $format === 'details-closed' ? FALSE : TRUE,
'#attributes' => $attributes,
'#children' => $children,
];
case 'fieldset':
$attributes['class'][] = 'webform-container';
$attributes['class'][] = 'webform-container-type-fieldset';
return [
'#type' => 'fieldset',
'#title' => $element['#title'],
'#id' => $element['#webform_id'],
'#attributes' => $attributes,
'#children' => $children,
];
case 'container':
$attributes['class'][] = 'webform-container';
return [
'#type' => 'container',
'#id' => $element['#webform_id'],
'#attributes' => $attributes,
'#children' => $children,
];
case 'header':
default:
return [
'#type' => 'webform_section',
'#id' => $element['#webform_id'],
'#title' => $element['#title'],
'#title_tag' => $this->configFactory
->get('webform.settings')
->get('element.default_section_title_tag'),
'#attributes' => $attributes,
] + $children;
}
}