You are here

function heartbeat_activity_stream_configure in Heartbeat 6.4

Callback function to configure a heartbeat stream

2 string references to 'heartbeat_activity_stream_configure'
hds_form_alter in modules/hds/hds.module
Implementation of hook_form_alter().
heartbeat_menu in ./heartbeat.module
Implementation of hook_menu().

File

./heartbeat.admin.inc, line 531
Admnistration tasks for heartbeat.

Code

function heartbeat_activity_stream_configure(&$form_state, $access_type) {
  $edit = $access_type['settings'];
  $form_state['stream'] = $edit;
  $class = drupal_strtolower($access_type['class']);
  $realname = isset($access_type['realname']) ? drupal_strtolower($access_type['realname']) : $class;
  drupal_set_title(t('Configure @type', array(
    '@type' => $access_type['name'],
  )));

  // Permissions, allow/deny message templates
  $form['fs_perms'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('Permissions'),
  );
  $messages = heartbeat_messages('all', FALSE, FALSE);
  $options = array(
    0 => t('No message selected'),
  );
  foreach ($messages as $message) {
    $options[$message['message_id']] = !empty($message['description']) ? $message['description'] : str_replace('_', ' ', $message['message_id']);
  }
  $form['fs_perms']['messages_denied'] = array(
    '#type' => 'select',
    '#title' => t('Choose message types you want to deny from display'),
    '#multiple' => TRUE,
    '#default_value' => isset($access_type['messages_denied']) ? $access_type['messages_denied'] : 0,
    '#options' => $options,
  );

  // Activate stream filters
  $form['fs_filters'] = array(
    '#type' => 'fieldset',
    '#title' => t('Filters'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['fs_filters']['display_filters'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable a list of message filters for pages'),
    '#default_value' => isset($access_type['display_filters']) ? $access_type['display_filters'] : 0,
  );
  $form['fs_filters']['display_block_filters'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable a list of message filters for block displays'),
    '#default_value' => isset($access_type['display_block_filters']) ? $access_type['display_block_filters'] : 0,
  );
  $form['fs_filters']['filters_cumul'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow filters to accumulate (like checkboxes). If not checked, filters will behave as radio buttons.'),
    '#default_value' => isset($access_type['filters_cumul']) ? $access_type['filters_cumul'] : 0,
  );
  $filters = variable_get('heartbeat_filters', array());
  $options = array_keys($filters);
  $form['fs_filters']['filters'] = array(
    '#type' => 'select',
    '#title' => t('Use these filters to show parts of the stream'),
    '#multiple' => TRUE,
    '#default_value' => isset($access_type['filters']) ? $access_type['filters'] : 0,
    '#options' => drupal_map_assoc($options),
  );

  // Stream settings
  $form['fs_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['fs_settings']['skip_active_user'] = array(
    '#type' => 'checkbox',
    '#title' => t('Skip active user'),
    '#default_value' => isset($edit['skip_active_user']) ? $edit['skip_active_user'] : 0,
    '#description' => t('Enabling this will make sure the active or logged-in user will not see his own messages.'),
  );
  $form['fs_settings']['poll_messages'] = array(
    '#type' => 'select',
    '#options' => array(
      0 => t('No'),
      10 => t('Every 10 seconds'),
      20 => t('Every 20 seconds'),
      30 => t('Every 30 seconds'),
      45 => t('Every 45 seconds'),
      60 => t('Every minute'),
    ),
    '#title' => t('Poll every x seconds for newer messages to prepend the stream.'),
    '#default_value' => isset($access_type['poll_messages']) ? $access_type['poll_messages'] : 0,
  );
  $form['fs_settings']['num_load_max'] = array(
    '#title' => t('Fetch a maximum of logged messages '),
    '#type' => 'textfield',
    '#size' => 20,
    '#description' => t('Heartbeat loads a maximum number of activity messages to keep a final number.
      This number has to be bigger than the number of max items in blocks and pages. This is needed because
      streams can have messages that are denied, grouped or inhibited by permission. In
      order to make sure we have enough messages for display and to keep the performance to a high level, this
      odd way is needed.'),
    '#default_value' => $edit['num_load_max'],
  );
  if (!empty($form_state['values']['grouping_seconds'])) {
    $value = $form_state['values']['grouping_seconds'];
  }
  elseif (isset($edit['grouping_seconds'])) {
    $value = $edit['grouping_seconds'];
  }
  else {
    $value = variable_get('heartbeat_activity_grouping_seconds', 7200);
  }
  $form['fs_settings']['grouping_seconds'] = array(
    '#title' => t('Maximum gap (in seconds)'),
    '#type' => 'textfield',
    '#size' => 40,
    '#default_value' => $value,
    '#description' => t('Leave the field to see the updated value. Currently set @value.', array(
      '@value' => _heartbeat_activity_get_time($value),
    )) . '<br />' . t('Maximum gap for the same activity to be grouped together and before an identical activity can be logged again'),
    '#prefix' => '<div id="heartbeat-tabs-2">',
    '#suffix' => '</div>',
    '#ahah' => array(
      'path' => 'heartbeat/ahah/grouping_seconds',
      'wrapper' => 'heartbeat-tabs-2',
      'event' => 'change',
      'method' => 'replace',
      'effect' => 'fade',
    ),
  );
  $form['fs_settings']['block_items_max'] = array(
    '#title' => t('Maximum items in the @name blocks', array(
      '@name' => $access_type['name'],
    )),
    '#type' => 'textfield',
    '#size' => 20,
    '#default_value' => $edit['block_items_max'],
  );
  $options = array(
    0 => t('No more link'),
    1 => t('Display "full list" link'),
    2 => t('Display an ajax-driven older messages link'),
    3 => t('Display an ajax-driven older messages link and a "full list" link'),
  );
  $form['fs_settings']['block_show_pager'] = array(
    '#title' => t('Show "older messages" link in block display'),
    '#type' => 'radios',
    '#options' => $options,
    '#default_value' => $edit['block_show_pager'],
  );
  $form['fs_settings']['page'] = array(
    '#type' => 'fieldset',
    '#title' => t('Page'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['fs_settings']['page']['page_disabled'] = array(
    '#title' => t('Disable the page for this stream'),
    '#type' => 'checkbox',
    '#default_value' => $edit['page_disabled'],
  );
  $form['fs_settings']['page']['page_items_max'] = array(
    '#title' => t('Maximum items in the @name pages', array(
      '@name' => $access_type['name'],
    )),
    '#type' => 'textfield',
    '#size' => 20,
    '#default_value' => $edit['page_items_max'],
  );
  $form['fs_settings']['page']['page_show_pager'] = array(
    '#title' => t('Display "older messages" link in page displays'),
    '#type' => 'checkbox',
    '#default_value' => $edit['page_show_pager'],
  );
  $form['fs_settings']['page']['page_pager_ajax'] = array(
    '#title' => t('Display "older messages" link in page displays with Ajax'),
    '#type' => 'checkbox',
    '#default_value' => $edit['page_pager_ajax'],
  );
  $form['fs_settings']['access_type'] = array(
    '#type' => 'value',
    '#value' => $realname,
  );
  $form['settings'] = array(
    '#tree' => TRUE,
  );

  // Give contributions the change to add extra properties.
  // Note that the auto-storage is triggered in the 'settings' key.
  heartbeat_include('heartbeatstream');
  heartbeat_include($class, $access_type['module'], $access_type['path']);
  $heartbeatAccess = new $class(new HeartbeatStream($access_type));
  $heartbeatAccess
    ->configurationForm($form, $form_state);
  $form['submit'] = array(
    '#type' => 'submit',
    '#title' => t('Submit'),
    '#value' => t('Submit'),
  );
  $form['#redirect'] = 'admin/build/heartbeat/streams';
  return $form;
}