You are here

function webform_workflow_state_access in Webform Workflow 7

Access callback for a workflow state.

Parameters

string $op: The operation to perform. Usually 'view', 'create', 'update', or 'delete'.

object|NULL $state: The state object.

object|NULL $account: The user account.

Return value

bool TRUE if access is granted, FALSE otherwise.

2 string references to 'webform_workflow_state_access'
webform_workflow_entity_info in ./webform_workflow.module
Implements hook_entity_info().
webform_workflow_menu in ./webform_workflow.module
Implements hook_menu().

File

./webform_workflow.module, line 75
A simple workflow module for webforms.

Code

function webform_workflow_state_access($op, $state = NULL, $account = NULL) {
  $account = $account ? $account : $GLOBALS['user'];

  // When creating a new state, or if no state is passed, allow access based on
  // whether the user is allowed to update the current webform node.
  if ($op === 'create' || !$state) {
    $node = menu_get_object('webform_menu');

    // Account for Inline Entity Form's AJAX callbacks, which mean that the node
    // ID is not available in the URL.
    if (!$node && !empty($_POST) && $_POST['form_id'] === 'webform_workflow_config_form' && drupal_valid_token($_POST['form_token'], $_POST['form_id'])) {
      return TRUE;
    }
    return FALSE;
  }

  // When checking access for an existing state, attempt to find whether it is
  // associated with a single webform node.
  $node = webform_workflow_state_get_node($state);
  if ($node) {
    return node_access('update', $node, $account);
  }

  // If the node could not be found, check the state's owner.
  return $state->uid && $account->uid === $state->uid;
}