You are here

function table_trash_admin_update_config_form in Table Trash 7

Menu callback for the update path.

1 string reference to 'table_trash_admin_update_config_form'
table_trash_menu in ./table_trash.module
Implements hook_menu().

File

./table_trash.admin.inc, line 137
table_trash.admin.inc

Code

function table_trash_admin_update_config_form($form, &$form_state) {
  ctools_include('export');

  // Retain tree-hierarchy in values, prevent the form from being flattened.
  $form['#tree'] = TRUE;

  // Check if our table exists and that our variable still exists.
  if (db_table_exists('table_trash') && ($decorations = variable_get('table_trash_decorations'))) {

    // Form fields to set a Name and Machine Name for each existing decoration.
    for ($i = 1; $i <= count($decorations); $i++) {
      $form['decorations'][$i] = array(
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#title' => t('Table decoration #@no', array(
          '@no' => $i,
        )),
      );
      $form['decorations'][$i]['name'] = array(
        '#type' => 'textfield',
        '#maxlength' => 64,
        '#title' => t('Decoration Name'),
      );
      $form['decorations'][$i]['machine_name'] = array(
        '#type' => 'machine_name',
        '#maxlength' => 64,
        '#title' => t('Machine Name'),
        '#machine_name' => array(
          'exists' => 'table_trash_decoration_load',
          'source' => array(
            'decorations',
            $i,
            'name',
          ),
          'label' => t('Machine Name'),
          'replace_pattern' => '[^a-z0-9-]+',
          'replace' => '_',
        ),
      );
    }
    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Update Stored Decorations'),
    );
    $form['#validate'][] = 'table_trash_validate_machine_names';
    $form['delete']['message'] = array(
      '#markup' => "This will permanently delete the table_trash_decorations variable. Only press this after using the 'Update Stored Decorations' button.<br>",
    );
    $form['delete']['delete_variable'] = array(
      '#type' => 'submit',
      '#value' => 'Delete table_trash_decorations Variable',
      '#weight' => 1,
      '#submit' => array(
        '_table_trash_delete_variable_submit',
      ),
      '#limit_validation_errors' => array(),
    );
  }
  else {
    $form['message'] = array(
      '#markup' => t('No updates needed.'),
    );
  }
  return $form;
}