Email.php in Webform 8.5
File
src/Plugin/WebformElement/Email.php
View source
<?php
namespace Drupal\webform\Plugin\WebformElement;
use Drupal\webform\WebformSubmissionInterface;
class Email extends TextBase {
protected function defineDefaultProperties() {
return [
'input_hide' => FALSE,
] + parent::defineDefaultProperties() + $this
->defineDefaultMultipleProperties();
}
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':
return [
'#type' => 'link',
'#title' => $value,
'#url' => \Drupal::pathValidator()
->getUrlIfValid('mailto:' . $value),
];
default:
return parent::formatHtmlItem($element, $webform_submission, $options);
}
}
public function getItemDefaultFormat() {
return 'link';
}
public function getItemFormats() {
return parent::getItemFormats() + [
'link' => $this
->t('Link'),
];
}
}
Classes
Name |
Description |
Email |
Provides a 'email' element. |