You are here

function autofill_field_widget_form_alter in Autofill 8

Implements hook_field_widget_form_alter().

File

./autofill.module, line 133
Contains autofill.module.

Code

function autofill_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {

  /** @var \Drupal\Core\Field\WidgetInterface $widget */
  $widget = $context['widget'];

  /** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
  $field_definition = $context['items']
    ->getFieldDefinition();
  if ($widget
    ->getThirdPartySetting('autofill', 'enabled') && ($source_field = $widget
    ->getThirdPartySetting('autofill', 'source_field'))) {
    $element['#attached']['library'][] = 'autofill/autofill';
    $element['#attached']['drupalSettings']['autofill']['field_mapping'][$field_definition
      ->getName()] = $source_field;
  }
}