You are here

function activity_module_settings in Activity 6

Same name and namespace in other branches
  1. 5.4 activity.module \activity_module_settings()

Activity module specific admin settings page.

1 string reference to 'activity_module_settings'
activity_menu in ./activity.module
Implementation of hook_menu().

File

./activity.module, line 277
activity.module

Code

function activity_module_settings(&$form_state, $module) {
  drupal_add_js(drupal_get_path('module', 'activity') . '/activity_admin.js');
  $module_nice_name = drupal_ucfirst(str_replace('_', ' ', substr($module, 0, -8)));
  $module_help = t('<p>The configuration settings below determine how activity generated by the <strong><em>@module</em></strong> module is recorded. Select which types of activity and which operations to record by checking/unchecking the options for <strong>Token Types</strong> and <strong>Operation Types</strong>. You can customize the text that is displayed on an activity record by changing the text in the fields below for each combination of token type and operation type and role.</p>', array(
    '@module' => $module_nice_name,
  ));
  $form['help'] = array(
    '#type' => 'markup',
    '#value' => $module_help,
  );
  $info = module_invoke($module, 'activity_info');
  if (!empty($info)) {
    $tokens = array();
    $token_list = array();
    foreach (token_get_list($module) as $name => $token_array) {
      $token_list = array_merge($token_list, $token_array);
    }
    foreach (token_get_list('activity') as $name => $token_array) {
      $token_list = array_merge($token_list, $token_array);
    }
    ksort($token_list);
    foreach ($token_list as $token => $desc) {
      $tokens[] = '[' . $token . ']: ' . $desc;
    }
    if (count($info['types'])) {
      $form['token_op_types'] = array(
        '#type' => 'fieldset',
        '#title' => t('Token and operation types'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
      );
      $form['token_op_types'][$module . '_token_types'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Token types'),
        '#description' => t('Select the token types that you wish to record activity from.'),
        '#options' => $info['types'],
        '#default_value' => variable_get($module . '_token_types', array_keys($info['types'])),
        '#attributes' => array(
          'class' => 'activity-token-types',
        ),
      );
      $form['token_op_types'][$module . '_op_types'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Operation types'),
        '#description' => t('Select the operation types that you wish to record activity from.'),
        '#options' => $info['ops'],
        '#default_value' => variable_get($module . '_op_types', array_keys($info['ops'])),
        '#attributes' => array(
          'class' => 'activity-operation-types',
        ),
      );
      $form['token_settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('Tokens available to @name activity', array(
          '@name' => t($module_nice_name),
        )),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#description' => t('Available tokens') . theme('item_list', $tokens),
      );
      if ($ops = $info['ops']) {
        if ($roles = $info['roles']) {
          foreach ($roles as $role_name => $role) {
            $form[$module][$role_name] = array(
              '#type' => 'fieldset',
              '#title' => t('Messages visible to the "@role_name" role.', array(
                '@role_name' => $role['#name'],
              )),
              '#collapsible' => TRUE,
              '#collapsed' => FALSE,
              '#description' => $role['#description'] ? $role['#description'] : '',
            );
            if ($types = $info['types']) {
              $token_types = variable_get($module . '_token_types', $info['types']);
              $op_types = variable_get($module . '_op_types', $info['ops']);
              foreach ($types as $type_name => $type) {
                if (count($types) > 1) {
                  $form[$module][$role_name][$type_name] = array(
                    '#type' => 'fieldset',
                    '#title' => t($type),
                    '#collapsible' => TRUE,
                    '#collapsed' => TRUE,
                  );
                }
                foreach ($ops as $op_name => $op) {
                  $token_field = "{$module}_{$type_name}_{$op_name}_{$role_name}";
                  $default = '';
                  if (!is_array($role['#default']) && $role['#default']) {
                    $default = $role['#default'];
                  }
                  else {
                    if (is_array($role['#default']) && isset($role['#default'][$op_name])) {
                      $default = $role['#default'][$op_name];
                    }
                  }
                  if ($default) {
                    $form[$module][$role_name][$type_name][$token_field] = array(
                      '#type' => 'textfield',
                      '#title' => $type . ': ' . $op,
                      '#default_value' => variable_get($token_field, $default),
                    );
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  return system_settings_form($form);
}