You are here

function _webform_allowed_roles in Webform 7.4

Helper. Generates an array of allowed roles.

Parameters

object $node: The loaded node object containing a webform.

bool $user_is_allowed: Reference to boolean to be set to whether the current user is allowed.

Return value

array Associative array of allowed roles indexed by the role id with a boolean value indicating if the current user has this role.

2 calls to _webform_allowed_roles()
webform_client_form_prevalidate in ./webform.module
Validates that the form can still be submitted, saved as draft, or edited.
webform_node_view in ./webform.module
Implements hook_node_view().

File

./webform.module, line 2133
This module provides a simple way to create forms and questionnaires.

Code

function _webform_allowed_roles($node, &$user_is_allowed) {
  global $user;
  if ($node->webform['confidential']) {

    // Confidential webform may only be submitted anonymously, including uid 1.
    $user_is_allowed = user_is_anonymous();
    $allowed_roles = array(
      DRUPAL_ANONYMOUS_RID => $user_is_allowed,
    );
  }
  elseif (webform_variable_get('webform_submission_access_control')) {

    // Check if the user's role can submit this webform.
    $allowed_roles = array();
    foreach ($node->webform['roles'] as $rid) {
      $allowed_roles[$rid] = isset($user->roles[$rid]);
    }
    $user_is_allowed = $user->uid == 1 || array_search(TRUE, $allowed_roles);
  }
  else {

    // If not using Webform submission access control, allow all roles.
    $user_is_allowed = TRUE;
    $allowed_roles = array_fill_keys(array_keys(user_roles()), TRUE);
  }
  return $allowed_roles;
}