This repository has been archived on 2025-09-29. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
drupalcampbristol/web/modules/contrib/webform/src/Element/WebformTelephone.php
2017-03-16 15:29:07 +00:00

58 lines
1.3 KiB
PHP

<?php
namespace Drupal\webform\Element;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a webform element for a telephone element.
*
* @FormElement("webform_telephone")
*/
class WebformTelephone extends WebformCompositeBase {
/**
* {@inheritdoc}
*/
public function getInfo() {
$info = parent::getInfo();
unset($info['#title_display']);
return $info;
}
/**
* {@inheritdoc}
*/
public static function getCompositeElements() {
$elements = [];
$elements['type'] = [
'#type' => 'select',
'#title' => t('Type'),
'#title_display' => 'invisible',
'#options' => 'phone_types',
'#empty_option' => t('- Type -'),
];
$elements['phone'] = [
'#type' => 'tel',
'#title' => t('Phone'),
'#title_display' => 'invisible',
'#international' => TRUE,
];
$elements['ext'] = [
'#title' => t('Ext:'),
'#type' => 'number',
'#size' => 5,
'#min' => 0,
];
return $elements;
}
/**
* Processes a composite webform element.
*/
public static function processWebformComposite(&$element, FormStateInterface $form_state, &$complete_form) {
$element = parent::processWebformComposite($element, $form_state, $complete_form);
$element['#attached']['library'][] = 'webform/webform.element.composite_telephone';
return $element;
}
}