You are here

function workflow_get_user_role_names in Workflow 8

Retrieves the names of roles matching specified conditions.

Deprecated D8: workflow_get_roles --> workflow_get_user_role_names.

Usage: D7: $roles = workflow_get_user_role_names('participate in workflow'); D8: $type_id = $workflow->id(); D8: $roles = workflow_get_user_role_names("create $type_id workflow_transition");

Parameters

string $permission: (optional) A string containing a permission. If set, only roles containing that permission are returned. Defaults to NULL, which returns all roles. Normal usage for filtering roles that are enabled in a workflow_type would be: $permission = 'create $type_id transition'.

Return value

array Array of role names keyed by role ID, including the 'author' role.

2 calls to workflow_get_user_role_names()
WorkflowAccessRoleForm::buildRow in modules/workflow_access/src/Form/WorkflowAccessRoleForm.php
WorkflowConfigTransitionRoleForm::buildRow in src/Form/WorkflowConfigTransitionRoleForm.php
Builds a row for the following table: Transitions, for example: 18 => [ 20 => [ 'author' => 1, 1 => 0, 2 => 1, ] ] means the transition from state 18 to state 20 can be executed by the content author or a user in…

File

./workflow.module, line 325
Support workflows made up of arbitrary states.

Code

function workflow_get_user_role_names($permission) {
  static $roles = NULL;
  if ($roles && isset($roles[$permission])) {
    return $roles[$permission];
  }

  // Copied from AccountForm::form().
  $roles[$permission] = array_map([
    '\\Drupal\\Component\\Utility\\Html',
    'escape',
  ], [
    WORKFLOW_ROLE_AUTHOR_RID => '(' . t(WORKFLOW_ROLE_AUTHOR_NAME) . ')',
  ] + user_role_names(FALSE, $permission));
  return $roles[$permission];
}