You are here

function mobile_number_field_widget_form in Mobile Number 7

Implements hook_field_widget_form().

File

./mobile_number.module, line 481
mobile_number.module

Code

function mobile_number_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $settings = $instance['widget']['settings'];
  $tfa_field = variable_get('mobile_number_tfa_field', '');
  $element += array(
    '#type' => 'mobile_number',
    '#description' => $element['#description'],
    '#default_value' => !empty($items[$delta]) ? $items[$delta] : array(),
    '#mobile_number' => array(
      'allowed_countries' => $settings['countries'],
      'verify' => mobile_number_sms_sending_is_enabled() ? $settings['verify'] : MOBILE_NUMBER_VERIFY_NONE,
      'message' => $settings['message'],
      'tfa' => $instance['entity_type'] == 'user' && $tfa_field && $tfa_field == $field['field_name'] && $field['cardinality'] == 1 ? TRUE : NULL,
      'token_data' => !empty($form['#entity']) ? array(
        $instance['entity_type'] => $form['#entity'],
      ) : array(),
      'field_title' => $instance['label'],
      'placeholder' => isset($settings['placeholder']) ? $settings['placeholder'] : NULL,
    ),
  );
  $element['#default_value'] += array(
    'country' => $settings['default_country'],
  );
  return $element;
}