protected function WebformElementBase::formatCustomItems in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElementBase.php \Drupal\webform\Plugin\WebformElementBase::formatCustomItems()
Format an element's items using custom HTML or plain text.
Parameters
string $type: The format type, HTML or Text.
array $element: An element.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
array $options: An array of options.
array $context: (optional) Context to be passed to inline Twig template.
Return value
array|string The element's items formatted as plain text or a render array.
1 call to WebformElementBase::formatCustomItems()
- WebformElementBase::format in src/
Plugin/ WebformElementBase.php - Format an element's value as HTML or plain text.
File
- src/
Plugin/ WebformElementBase.php, line 1377
Class
- WebformElementBase
- Provides a base class for a webform element.
Namespace
Drupal\webform\PluginCode
protected function formatCustomItems($type, array &$element, WebformSubmissionInterface $webform_submission, array $options = [], array $context = []) {
$name = strtolower($type);
// Get value.
$value = $this
->getValue($element, $webform_submission, $options);
// Get items.
$items = [];
$item_function = 'format' . $type . 'Item';
foreach (array_keys($value) as $delta) {
$items[] = $this
->{$item_function}($element, $webform_submission, [
'delta' => $delta,
] + $options);
}
// Get template.
$template = trim($element['#format_items_' . $name]);
// Get context.
$options += [
'context' => [],
];
$context += [
'value' => $value,
'items' => $items,
];
return WebformTwigExtension::buildTwigTemplate($webform_submission, $template, $options, $context);
}