Skip to content

Instantly share code, notes, and snippets.

@clrockwell
Created January 13, 2017 21:12
Show Gist options
  • Save clrockwell/69ce2e1be6cd6cf3c7eda510eeabd957 to your computer and use it in GitHub Desktop.
Save clrockwell/69ce2e1be6cd6cf3c7eda510eeabd957 to your computer and use it in GitHub Desktop.
<?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