You are here

function twilio_admin_form in Twilio 7

Administration form for twilio settings.

1 string reference to 'twilio_admin_form'
twilio_menu in ./twilio.module
Implements hook_menu().

File

./twilio.admin.inc, line 10
Administrative forms section

Code

function twilio_admin_form($form, &$form_state) {

  // Detect the Twilio library and provide feedback to the user if not present.
  if (module_exists('libraries') && function_exists('libraries_detect')) {
    $library = libraries_detect(TWILIO_LIBRARY);
    if (!$library['installed']) {
      $twilio_readme_link = l(t('README.txt'), 'http://drupalcode.org/project/twilio.git/blob/refs/heads/7.x-1.x:/README.txt');
      $twilio_error_text = t('The Twilo library was not detected or installed correctly. Please review the installation instructions provided in the !link file', array(
        '!link' => $twilio_readme_link,
      ));
      drupal_set_message($twilio_error_text, 'error');
    }
  }
  $form['twilio_account'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => t('Twilio Account SID'),
    '#default_value' => variable_get('twilio_account'),
    '#description' => t('Enter your Twilio account id'),
  );
  $form['twilio_token'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => t('Twilio Auth Token'),
    '#default_value' => variable_get('twilio_token'),
    '#description' => t('Enter your Twilio token id'),
  );
  $form['twilio_number'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => t('Twilio Phone Number'),
    '#default_value' => variable_get('twilio_number'),
    '#description' => t('Enter your Twilio phone number'),
  );
  $form['twilio_long_sms'] = array(
    '#type' => 'radios',
    '#title' => t('Long SMS handling'),
    '#description' => t('How would you like to handle SMS messages longer than 160 characters.'),
    '#options' => array(
      t('Send multiple messages'),
      t('Truncate message to 160 characters'),
    ),
    '#default_value' => variable_get('twilio_long_sms', TWILIO_SMS_LONG_MULTIPLE),
  );
  $form['twilio_registration_form'] = array(
    '#type' => 'radios',
    '#title' => t('Show mobile fields during user registration'),
    '#description' => t('Specify if the site should collect mobile information during registration.'),
    '#options' => array(
      t('Disabled'),
      t('Optional'),
      t('Required'),
    ),
    '#default_value' => variable_get('twilio_registration_form', 0),
  );
  $form['twilio_country_codes_container'] = array(
    '#type' => 'fieldset',
    '#title' => t('Country codes'),
    '#description' => t('Select the country codes you would like available, If none are selected all will be available.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['twilio_country_codes_container']['twilio_country_codes'] = array(
    '#type' => 'checkboxes',
    '#options' => twilio_country_codes(TRUE),
    '#default_value' => variable_get('twilio_country_codes', array()),
  );

  // Expose the callback URLs to the user for convenience.
  $form['twilio_callback_container'] = array(
    '#type' => 'fieldset',
    '#title' => t('Module callbacks'),
    '#description' => t('Enter these callback addresses into your Twilio phone number configuration on the Twilio dashboard to allow your site to respond to incoming voice calls and SMS messages.'),
  );

  // Initialize URL variables.
  $voice_callback = $GLOBALS['base_url'] . '/twilio/voice';
  $sms_callback = $GLOBALS['base_url'] . '/twilio/sms';
  $form['twilio_callback_container']['voice_callback'] = array(
    '#type' => 'item',
    '#title' => t('Voice request URL'),
    '#markup' => '<p>' . $voice_callback . '</p>',
  );
  $form['twilio_callback_container']['sms_callback'] = array(
    '#type' => 'item',
    '#title' => t('SMS request URL'),
    '#markup' => '<p>' . $sms_callback . '</p>',
  );
  return system_settings_form($form);
}