You are here

function _update_advanced_alter_settings in Update Status Advanced Settings 7

Same name and namespace in other branches
  1. 6 update_advanced.settings.inc \_update_advanced_alter_settings()

Alters the update_settings form to add per-project settings.

1 call to _update_advanced_alter_settings()
update_advanced_form_update_settings_alter in ./update_advanced.module
Implements hook_form_FORM_ID_alter().

File

./update_advanced.settings.inc, line 11
Code only required on the settings tab of the update status page.

Code

function _update_advanced_alter_settings(&$form, $form_state) {
  $available = update_get_available(TRUE);
  if (!$available) {
    return;
  }
  $form['#theme'] = 'update_advanced_settings';
  $form['#attached']['css'][] = drupal_get_path('module', 'update_advanced') . '/update_advanced.css';
  $values = variable_get('update_advanced_project_settings', array());
  $form['update_advanced_project_settings'] = array(
    '#tree' => TRUE,
  );
  module_load_include('inc', 'update', 'update.compare');
  $data = update_calculate_project_data($available);
  $form['data'] = array(
    '#type' => 'value',
    '#value' => $data,
  );
  $form['available'] = array(
    '#type' => 'value',
    '#value' => $available,
  );

  // We need to call our own submit callback first, not the one from
  // update_settings_form, so that we can unset 'data' and 'available'
  // before they are saved into the {variables} table.
  array_unshift($form['#submit'], 'update_advanced_settings_submit');
  $form['update_advanced_project_settings_help'] = array(
    '#markup' => t('These settings allow you to control if a certain project, or even a specific release of that project, should be ignored by the available updates report. For each project, you can select if it should always warn you about a newer release, never warn you (ignore the project completely), or ignore a specific available release you do not want to upgrade to. You can also specify a note explaining why you are ignoring a specific project or version, and that will be displayed on the available updates report.'),
  );
  foreach ($data as $key => $project) {
    if (isset($available[$key])) {
      if (!isset($values[$key])) {
        $values[$key] = array(
          'check' => 'always',
          'notes' => '',
        );
      }
      $options = array();
      $options['always'] = t('Always');
      if (isset($project['recommended'])) {
        $options[$project['recommended']] = t('Ignore @version', array(
          '@version' => $project['recommended'],
        ));
      }
      $options['never'] = t('Never');
      $form['update_advanced_project_settings'][$key]['check'] = array(
        '#type' => 'select',
        '#options' => $options,
        '#default_value' => $values[$key]['check'],
      );
      $form['update_advanced_project_settings'][$key]['notes'] = array(
        '#type' => 'textfield',
        '#size' => 50,
        '#default_value' => $values[$key]['notes'],
      );
    }
  }
}