protected function WebformEmailMultiple::formatHtmlItem in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/WebformEmailMultiple.php \Drupal\webform\Plugin\WebformElement\WebformEmailMultiple::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 Email::formatHtmlItem
File
- src/
Plugin/ WebformElement/ WebformEmailMultiple.php, line 55
Class
- WebformEmailMultiple
- Provides a 'email_multiple' element.
Namespace
Drupal\webform\Plugin\WebformElementCode
protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$value = $this
->getValue($element, $webform_submission, $options);
if (empty($value)) {
return '';
}
$format = $this
->getItemFormat($element);
switch ($format) {
case 'link':
$emails = preg_split('/\\s*,\\s*/', $value);
$total = count($emails);
$i = 0;
$links = [];
foreach ($emails as $email) {
$links[] = [
'#type' => 'link',
'#title' => $email,
'#url' => $this->pathValidator
->getUrlIfValid('mailto:' . $email),
'#suffix' => ++$i !== $total ? ', ' : '',
];
}
return $links;
default:
return parent::formatHtmlItem($element, $webform_submission, $options);
}
}