You are here

function system_settings_deploy_form_alter in Deploy - Content Staging 6

Same name and namespace in other branches
  1. 5 system_settings_deploy/system_settings_deploy.module \system_settings_deploy_form_alter()

Implementation of hook_form_alter().

Adds the deployment plan drop down to all forms built using system_settings_form(),

File

modules/system_settings_deploy/system_settings_deploy.module, line 15
Deployment API which enables modules to deploy items between servers.

Code

function system_settings_deploy_form_alter(&$form, $form_state, $form_id) {

  // If user doesn't have permissions then bail.
  if (!user_access('add items to deployment plan')) {
    return;
  }
  if (isset($form['#submit']) && in_array('system_settings_form_submit', $form['#submit'])) {

    // Set our drop down's weight to be one lighter than the submit button's,
    // ensuring that it always appears right above it (assuming nobody else
    // form_alter()s us out.)
    $weight = isset($form['buttons']['#weight']) ? $form['buttons']['#weight'] : 0;
    $form['buttons']['#weight'] = $weight + 1;
    $deploy_weight = $weight;
    $form['#submit'][] = 'system_settings_deploy_form_submit';
    $plans = deploy_get_plan_options();
    if (!empty($plans)) {
      $plans['0'] = '<None>';
      natsort($plans);
      $form['deploy']['deploy_plan'] = array(
        '#type' => 'select',
        '#title' => t('Deployment Plan'),
        '#description' => t('A deployment plan to add these settings to, or none'),
        '#weight' => $deploy_weight,
        '#options' => $plans,
      );
    }
  }
}