protected function GroupMembershipController::attachLoad in Group 7
Add group roles to group memberships upon loading.
This will load the memberships' roles before it is passed onto any hooks that act upon entity loading.
Overrides DrupalDefaultEntityController::attachLoad
File
- classes/
group_membership.controller.inc, line 18 - Defines the Entity API CRUD class for group memberships.
Class
- GroupMembershipController
- Controller for group membership entities.
Code
protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
if ($queried_entities) {
// Gather all loaded memberships' role data.
$query = db_select('group_membership_role', 'gmr')
->fields('gmr', array(
'mid',
'role',
))
->condition('mid', array_keys($queried_entities), 'IN');
// Gather the roles per group membership id.
foreach ($query
->execute() as $record) {
$roles[$record->mid][] = $record->role;
}
// Add the group roles onto the memberships.
foreach ($queried_entities as $mid => $group_membership) {
$group_membership->roles = isset($roles[$mid]) ? $roles[$mid] : array();
}
}
// Invoke the other attachLoad functionality.
parent::attachLoad($queried_entities, $revision_id);
}