You are here

system_settings_deploy.module in Deploy - Content Staging 5

File

system_settings_deploy/system_settings_deploy.module
View source
<?php

/**
 * Add deployment fields to all system settings forms.
 */
function system_settings_deploy_form_alter($form_id, &$form) {
  if (!user_access('add items to deployment plan')) {
    return;
  }

  // Shift system_settings_form buttons.
  if (isset($form['#base']) && $form['#base'] == 'system_settings_form') {
    $weight = $form['buttons']['#weight'];
    $form['buttons']['#weight'] = $weight + 1;
    $deploy_weight = $weight;
    $form['#submit'] = array(
      'system_settings_deploy_form_submit' => array(),
    ) + (array) $form['#submit'];
    $plans = deploy_get_plans();
    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,
      );
    }
  }
}

/**
 * submit handler for systems settings forms that have deployment enabled
 */
function system_settings_deploy_form_submit($form_id, $form_values) {
  $pid = $form_values['deploy_plan'];

  // remove the "deploy_plan" key from form_values before
  // we save the array, since its stupid on the other side
  if (array_key_exists("deploy_plan", $form_values)) {
    unset($form_values["deploy_plan"]);
  }

  // serialize and save $form_values
  $data = serialize($form_values);

  // if a deployment plan is submitted then add these settings
  if ($pid != '0') {
    deploy_add_to_plan($pid, 'system_settings', 'Settings: ' . $form_id, $data);
  }

  // either way we still want to update any existing plans that include these
  // settings with these changes
  $result = db_query("select * from {deploy_plan_items} where module = 'system_settings'");
  while ($row = db_fetch_array($result)) {
    deploy_update_item($row['iid'], $data);
  }
}

/**
 * deployment "hook"
 */
function system_settings_deploy($url, $api_key, $data) {
  return xmlrpc($url, 'system_settings.import', $api_key, unserialize($data));
}

Functions

Namesort descending Description
system_settings_deploy deployment "hook"
system_settings_deploy_form_alter Add deployment fields to all system settings forms.
system_settings_deploy_form_submit submit handler for systems settings forms that have deployment enabled