You are here

public function GroupRoleSynchronizer::getGroupRoleId in Group 8

Same name and namespace in other branches
  1. 2.0.x src/GroupRoleSynchronizer.php \Drupal\group\GroupRoleSynchronizer::getGroupRoleId()

Generates an ID for a synchronized group role.

Parameters

$group_type_id: The ID of the group type the group role ID should be generated for.

$role_id: The ID of the user role the group role ID should be generated for.

Return value

string The group role ID for the given group type and user role.

Overrides GroupRoleSynchronizerInterface::getGroupRoleId

2 calls to GroupRoleSynchronizer::getGroupRoleId()
GroupRoleSynchronizer::getGroupRoleIdsByGroupTypes in src/GroupRoleSynchronizer.php
Retrieves all synchronized group role IDs for a list of group types.
GroupRoleSynchronizer::getGroupRoleIdsByUserRoles in src/GroupRoleSynchronizer.php
Retrieves all synchronized group role IDs for a list of user roles.

File

src/GroupRoleSynchronizer.php, line 35

Class

GroupRoleSynchronizer
Synchronizes user roles to group roles.

Namespace

Drupal\group

Code

public function getGroupRoleId($group_type_id, $role_id) {

  // The maximum length of a group role's machine name.
  //
  // Group role IDs consist of two parts separated by a dash:
  // - The group type ID.
  // - The machine name of the group role; unique per group type.
  //
  // Therefore, the maximum length of a group role machine name is determined
  // by subtracting the group type ID length from the entity type ID length
  // and leaving room for a dash character.
  $machine_name_max_length = EntityTypeInterface::ID_MAX_LENGTH - GroupTypeInterface::ID_MAX_LENGTH - 1;

  // Generate an MD5 hash to use as the group role machine name.
  $machine_name = substr(md5('group_role_sync.' . $role_id), 0, $machine_name_max_length);
  return "{$group_type_id}-{$machine_name}";
}