You are here

function taxonomy_access_enable_role_validate in Taxonomy Access Control 7

Page callback: Enables a role if the proper token is provided.

Parameters

int $rid: The role ID.

1 string reference to 'taxonomy_access_enable_role_validate'
taxonomy_access_menu in ./taxonomy_access.module
Implements hook_menu().

File

./taxonomy_access.admin.inc, line 127
Administrative interface for taxonomy access control.

Code

function taxonomy_access_enable_role_validate($rid) {
  $rid = intval($rid);

  // If a valid token is not provided, return a 403.
  $query = drupal_get_query_parameters();
  if (empty($query['token']) || !drupal_valid_token($query['token'], $rid)) {
    return MENU_ACCESS_DENIED;
  }

  // Return a 404 for the anonymous or authenticated roles.
  if (in_array($rid, array(
    DRUPAL_ANONYMOUS_RID,
    DRUPAL_AUTHENTICATED_RID,
  ))) {
    return MENU_NOT_FOUND;
  }

  // Return a 404 for invalid role IDs.
  $roles = _taxonomy_access_user_roles();
  if (empty($roles[$rid])) {
    return MENU_NOT_FOUND;
  }

  // If the parameters pass validation, enable the role and complete redirect.
  if (taxonomy_access_enable_role($rid)) {
    drupal_set_message(t('Role %name enabled successfully.', array(
      '%name' => $roles[$rid],
    )));
  }
  drupal_goto();
}