Email.php in YAML Form 8
File
src/Plugin/YamlFormElement/Email.php
View source
<?php
namespace Drupal\yamlform\Plugin\YamlFormElement;
use Drupal\yamlform\YamlFormElementBase;
class Email extends YamlFormElementBase {
public function getDefaultProperties() {
return parent::getDefaultProperties() + [
'size' => '',
'maxlength' => '',
'placeholder' => '',
];
}
public function formatHtml(array &$element, $value, array $options = []) {
if (empty($value)) {
return '';
}
$format = $this
->getFormat($element);
switch ($format) {
case 'link':
return [
'#type' => 'link',
'#title' => $value,
'#url' => \Drupal::pathValidator()
->getUrlIfValid('mailto:' . $value),
];
default:
return parent::formatHtml($element, $value, $options);
}
}
public function getDefaultFormat() {
return 'link';
}
public function getFormats() {
return parent::getFormats() + [
'link' => $this
->t('Link'),
];
}
}
Classes
Name |
Description |
Email |
Provides a 'email' element. |