You are here

function pmpapi_config_form in Public Media Platform API Integration 7

Form constructor for the PMPAPI admin form.

See also

pmpapi_config_form_validate()

pmpapi_config_form_submit()

1 string reference to 'pmpapi_config_form'
pmpapi_menu in ./pmpapi.module
Implements hook_menu().

File

./pmpapi.admin.inc, line 16
Basic admin forms, validators, and submit handlers for the PMPAPI module.

Code

function pmpapi_config_form($form, &$form_state) {

  // Only run this if there are already credentials available.
  // Don't worry about calls to this function where there is a non-empty input
  // in $form_state, as this is a second call happening on submission. No need
  // to ping the API twice.
  if (variable_get('pmpapi_base_url') && variable_get('pmpapi_user_id') && variable_get('pmpapi_auth_client_id') && variable_get('pmpapi_auth_client_secret') && empty($form_state['input'])) {
    if (pmpapi_ping()) {
      $type = 'status';
      $message = t('Ping to API came back without errors.');
    }
    else {
      $type = 'warning';
      $message = t('Ping to API came back with errors.');
    }
    drupal_set_message($message, $type, FALSE);
  }
  $form['pmpapi_base_url'] = array(
    '#type' => 'select',
    '#required' => TRUE,
    '#title' => t('Platform'),
    '#default_value' => variable_get('pmpapi_base_url'),
    '#options' => array(
      'https://api-sandbox.pmp.io' => 'sandbox',
      'https://api.pmp.io' => 'production',
    ),
  );
  $form['pmpapi_user_id'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => t('User/Org GUID'),
    '#default_value' => variable_get('pmpapi_user_id'),
  );
  $form['pmpapi_auth_client_id'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => t('Authentication Client ID'),
    '#default_value' => variable_get('pmpapi_auth_client_id'),
  );
  $form['pmpapi_auth_client_secret'] = array(
    '#type' => 'textfield',
    '#required' => TRUE,
    '#title' => t('Authentication Client Secret'),
    '#default_value' => variable_get('pmpapi_auth_client_secret'),
  );
  $custom_caches = pmpapi_get_custom_caches();
  if (variable_get('pmpapi_cache') && $custom_caches) {
    $form['pmpapi_cache_bin'] = array(
      '#type' => 'select',
      '#title' => t('Cache bin'),
      '#default_value' => variable_get('pmpapi_cache_bin', 'cache'),
      '#options' => drupal_map_assoc(array_merge(array(
        'cache',
      ), $custom_caches)),
    );
  }
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  return $form;
}