You are here

function macro_form_alter in Macro 6

Same name and namespace in other branches
  1. 7 macro.module \macro_form_alter()

Implementation of hook_form_alter().

File

./macro.module, line 95
allow administrators to record (export) form submissions allow administrators to replay (import) form submissions

Code

function macro_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'macro_export_macro':

      /** TODO: eventually add file saving with foldering options.
          $form['file-save'] = array('#type' => 'fieldset', '#title' => 'Save To File', '#description' => '');
          $form['file-save']['filename'] = array('#type' => 'textfield', '#title' => 'Filename');
          $form['file-save]['save'] = array('#type' => 'submit', '#value' => 'Save', '#submit' => array('macro_export_file_save_submit'));
          */
      break;

    // Forms to specifically ignore for macro.
    case 'macro_admin_settings':
    case 'macro_import_macro':
    case 'macro_export_macro':
      break;
    default:

      // Add import / export buttons to each form for simplified macro saving.
      if (user_access('macro access') && variable_get('macro_display_actions', FALSE)) {
        $form['macro-actions'] = array(
          '#type' => 'fieldset',
          '#title' => t('Macro actions'),
          '#weight' => 5000,
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
        );
        $form['macro-actions']['import-data'] = array(
          '#type' => 'submit',
          '#name' => 'import',
          '#value' => t('Import'),
          '#submit' => array(
            'macro_import_action_submit',
          ),
        );
        $form['macro-actions']['export-data'] = array(
          '#type' => 'submit',
          '#name' => 'export',
          '#value' => t('Export'),
          '#submit' => array(
            'macro_export_action_submit',
          ),
        );
        if (!variable_get('macro_enabled', FALSE)) {
          $form['macro-actions']['export-session-data'] = array(
            '#type' => 'submit',
            '#value' => t('Start session'),
            '#submit' => array(
              'macro_export_session_action_submit',
            ),
          );
        }
      }

      // Add the record callback on submit.
      if ($form_id != 'macro_import_macro' && variable_get('macro_enabled', FALSE)) {
        $form['#submit'][] = 'macro_record_macro';
      }

      // Clear the current sessions.
      if (variable_get('macro_delete', FALSE)) {
        variable_set('macro_submissions', array());
        variable_set('macro_delete', FALSE);
      }
      break;
  }
}