You are here

function parse_roles in LTI Tool Provider 8

Same name and namespace in other branches
  1. 2.x lti_tool_provider.module \parse_roles()

Utility function to get an array of fully qualified LTI user roles.

Parameters

mixed $roles: Comma-separated list of roles or array of roles.

Return value

array An array of roles

2 calls to parse_roles()
LtiToolProviderProvisionEventSubscriber::onCreateProvision in modules/lti_tool_provider_provision/src/EventSubscriber/LtiToolProviderProvisionEventSubscriber.php
LtiToolProviderRolesEventSubscriber::onAuthenticated in modules/lti_tool_provider_roles/src/EventSubscriber/LtiToolProviderRolesEventSubscriber.php

File

./lti_tool_provider.module, line 61
LTI Tool Provider hook implementations and support functions.

Code

function parse_roles($roles) : array {
  $parsedRoles = [];
  if (!is_array($roles)) {
    $roles = explode(',', $roles);
  }
  foreach ($roles as $role) {
    $role = trim($role);
    if (!empty($role)) {
      if (substr($role, 0, 4) !== 'urn:') {
        $role = 'urn:lti:role:ims/lis/' . $role;
      }
      $parsedRoles[] = $role;
    }
  }
  return $parsedRoles;
}