You are here

function variablecheck_check_variables_form in Variable Check 7

Helper that displays a form which allows users to delete variables that fail to unserialize, causing ugly Notices on production sites.

1 string reference to 'variablecheck_check_variables_form'
variablecheck_menu in ./variablecheck.module
Implementation of hook_menu().

File

./variablecheck.module, line 92

Code

function variablecheck_check_variables_form($form, $form_state) {
  if (isset($form_state['values']['submit']) && $form_state['values']['submit'] == 'Delete') {
    return variablecheck_delete_confirm($form, $form_state, array_filter($form_state['values']['variables']));
  }
  $options = variablecheck_check_variables();
  $header = array(
    'name' => t('Name'),
    'value' => t('Value'),
  );
  drupal_set_title(t('Invalid Variables'));
  if ($count = count($options)) {
    drupal_set_message(format_plural($count, 'Found one invalid variable', 'Found @count invalid variables'), 'error');
    $info = format_plural($count, 'You will want to either delete this variable or let the module developer know there is a problem with their module.', 'You will want to either delete these variables or let the module developer know there is a problem with their module.');
  }
  else {
    $info = t('');
  }
  $form = array();
  $form['info'] = array(
    '#markup' => $info,
  );
  $form['variables'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No invalid variables found'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Delete'),
    '#access' => !empty($options) ? TRUE : FALSE,
  );
  return $form;
}