You are here

function _pm_block_user_actions_form in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 pm_block_user/pm_block_user.admin.inc \_pm_block_user_actions_form()
  2. 6 pm_block_user/pm_block_user.module \_pm_block_user_actions_form()
  3. 7.2 pm_block_user/pm_block_user.admin.inc \_pm_block_user_actions_form()

Builds row of sending, receiving roles and actions that go with them.

Parameters

$details: Details of the row: default values and the unique row number (delta).

$blacklist: When the functionality has been added, this will allow building actions based on a whitelist or blacklist. The current code only covers the use case of a blacklist, where blocking everyone is allowed by default and rules are exceptions to that. Conversely, a whitelist will disallow blocking by default and rules will configure roles that are allowed to block.

Return value

Part of a form with controls for sending, receiving and actions.

1 call to _pm_block_user_actions_form()
pm_block_user_settings in pm_block_user/pm_block_user.admin.inc
Menu callback for blocked user settings.

File

pm_block_user/pm_block_user.admin.inc, line 24
Administration menu callbacks for pm_block_user.module.

Code

function _pm_block_user_actions_form($details, $blacklist = TRUE) {
  $form = array(
    '#tree' => TRUE,
  );
  $delta = $details['delta'];

  // FALSE by default, or if the user has checked the 'Enabled' check box for
  // this row.
  $row_disabled = isset($details['enabled']) ? !$details['enabled'] : FALSE;
  $form['author'] = array(
    '#type' => 'select',
    '#options' => user_roles(TRUE),
    '#default_value' => isset($details['author']) ? $details['author'] : DRUPAL_AUTHENTICATED_RID,
    '#disabled' => $row_disabled,
  );
  $form['recipient'] = array(
    '#type' => 'select',
    '#options' => user_roles(TRUE),
    '#default_value' => isset($details['recipient']) ? $details['recipient'] : DRUPAL_AUTHENTICATED_RID,
    '#disabled' => $row_disabled,
  );

  // Provide different action radios if we're using a whitelist or a blacklist.
  if ($blacklist) {
    $options = array(
      PM_BLOCK_USER_DISALLOW_BLOCKING => t('Disallow blocking author'),
      PM_BLOCK_USER_DISALLOW_SENDING => t('Disallow sending message'),
    );
    $default_value = isset($details['action']) ? $details['action'] : PM_BLOCK_USER_DISALLOW_BLOCKING;
  }
  else {

    // TODO: add whitelist options/default_value here.
  }
  $form['action'] = array(
    '#type' => 'radios',
    '#options' => $options,
    '#disabled' => $row_disabled,
    '#default_value' => $default_value,
  );
  $form['enabled'] = array(
    '#type' => 'checkbox',
    '#default_value' => isset($details['enabled']) ? $details['enabled'] : TRUE,
  );
  $form['remove'] = array(
    '#type' => 'submit',
    '#submit' => array(
      'pm_block_user_remove_submit',
    ),
    '#value' => t('Remove_' . $delta),
    '#attributes' => array(
      'class' => array(
        'remove-action',
      ),
    ),
    '#prefix' => '<div id="remove-rule-button">',
    '#suffix' => '<label for="edit-remove">' . t('Remove rule') . '</label></div>',
    '#ajax' => array(
      'callback' => 'pm_block_user_js',
      'wrapper' => 'block-actions',
    ),
  );
  return $form;
}