Created
January 13, 2017 21:12
-
-
Save clrockwell/69ce2e1be6cd6cf3c7eda510eeabd957 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\mymodule\Plugin\Field\FieldWidget; | |
use Drupal\telephone\Plugin\Field\FieldWidget\TelephoneDefaultWidget; | |
/** | |
* Plugin implementation of the 'telephone_input_mask' widget. | |
* | |
* @FieldWidget( | |
* id = "telephone_input_mask", | |
* label = @Translation("Telephone number with input mask"), | |
* field_types = { | |
* "telephone" | |
* } | |
* ) | |
*/ | |
class TelephoneWidget extends TelephoneDefaultWidget { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { | |
$element['value'] = $element + array( | |
'#type' => 'tel', | |
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL, | |
'#placeholder' => $this->getSetting('placeholder'), | |
''#attached' => ['library' => 'mymodule/input-mask'] | |
); | |
return $element; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment