You are here

function privatemsg_filter_dropdown in Privatemsg 7.2

Same name and namespace in other branches
  1. 6.2 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_dropdown()
  2. 6 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_dropdown()
  3. 7 privatemsg_filter/privatemsg_filter.module \privatemsg_filter_dropdown()
1 call to privatemsg_filter_dropdown()
privatemsg_filter_form_privatemsg_list_alter in privatemsg_filter/privatemsg_filter.module
Implements hook_form_FORM_ID_alter() to add a filter widget to the message listing pages.

File

privatemsg_filter/privatemsg_filter.module, line 329
Allows users to tag private messages and to filter based upon those tags.

Code

function privatemsg_filter_dropdown(&$form_state, $account) {
  $form['#attached']['css'][] = drupal_get_path('module', 'privatemsg_filter') . '/privatemsg_filter.css';
  $form['filter'] = array(
    '#type' => 'fieldset',
    '#title' => t('Filter Messages'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => -20,
    // The form is always called when search arguments are passed in, even if
    // they don't have access to it. This is necessary to process the search
    // query. But we don't want to show them the form.
    '#access' => privatemsg_user_access('filter private messages'),
  );
  $form['filter']['search'] = array(
    '#type' => 'textfield',
    '#title' => variable_get('privatemsg_filter_searchbody', FALSE) ? t('By message text') : t('By subject'),
    '#weight' => -20,
    '#size' => 25,
  );
  $form['filter']['author'] = array(
    '#type' => 'textfield',
    '#title' => t('By participant'),
    '#weight' => -5,
    '#size' => 25,
    '#autocomplete_path' => 'messages/filter/autocomplete',
  );

  // Only show form if the user has some messages tagged.
  if (count($tag_data = privatemsg_filter_get_tags_data($account))) {
    $form['filter']['tags'] = array(
      '#type' => 'select',
      '#title' => t('By tags'),
      '#options' => $tag_data,
      '#multiple' => TRUE,
      '#weight' => 0,
    );
  }
  $form['filter']['actions'] = array(
    '#type' => 'actions',
    '#attributes' => array(
      'class' => array(
        'privatemsg-filter-actions',
      ),
    ),
  );
  $form['filter']['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Filter'),
    '#weight' => 10,
    '#submit' => array(
      'privatemsg_filter_dropdown_submit',
    ),
  );
  $form['filter']['actions']['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save filter'),
    '#weight' => 11,
    '#submit' => array(
      'privatemsg_filter_dropdown_submit',
    ),
  );
  if ($filter = privatemsg_filter_get_filter($account)) {

    // Display a message if the user will not see the filter form.
    if (!empty($filter['tags']) && !empty($_GET['tags']) && !privatemsg_user_access('filter private messages')) {
      drupal_set_message(t('Messages tagged with %tags are currently displayed. <a href="@remove_filter_url">Click here to remove this filter</a>.', array(
        '%tags' => $_GET['tags'],
        '@remove_filter_url' => url($_GET['q']),
      )));
    }
    privatemsg_filter_dropdown_set_active($form, $filter);
  }
  return $form;
}