You are here

public static function CpfCnpjElement::processMask in Brazilian IDs 8

Processes Form API elements to add mask.

Parameters

array $element: The element being processed.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the form the element belongs to.

array $complete_form: The form the element belongs to.

Return value

array The processed element.

File

src/Element/CpfCnpjElement.php, line 41

Class

CpfCnpjElement
Plugin annotation @FormElement("brazilian_ids_cpf_cnpj");

Namespace

Drupal\brazilian_ids\Element

Code

public static function processMask(array &$element, FormStateInterface $form_state, array &$complete_form) {
  if (\Drupal::moduleHandler()
    ->moduleExists('mask')) {

    // The mask is set up by JavaScript.
    $element['#attributes']['class'][] = 'brazilian-ids-cpf-cnpj-mask';
    $element['#attached']['library'][] = 'brazilian_ids/brazilian_ids_mask';
  }
  return $element;
}