You are here

function userprotect_views_bulk_operations_form_alter in User protect 7

Implements hook_views_bulk_operations_form_alter().

Ensures user protections are respected in VBO views.

File

./userprotect.module, line 167
Main module file for the userprotect module.

Code

function userprotect_views_bulk_operations_form_alter(&$form, $form_state, $vbo) {

  // VBO <= 3.3 uses the 'users' table. VBO => 3.4 uses views_entity_user.
  // Checking for two table names to keep compatibility with both VBO versions.
  // See https://www.drupal.org/node/1635520.
  if ($vbo->table != 'views_entity_user' && $vbo->table != 'users') {
    return;
  }

  // Alter the appropiate form submitter.
  $form_element = NULL;
  if (isset($form['select']['submit']['#submit'])) {
    $form_element =& $form['select']['submit'];
  }
  elseif (isset($form['actions']['submit']['#submit'])) {
    $form_element =& $form['actions']['submit'];
  }
  else {
    $form_element =& $form;
  }
  $form_element['#validate'] = isset($form_element['#validate']) ? $form_element['#validate'] : array();
  array_unshift($form_element['#validate'], 'userprotect_user_admin_account_validate');
}