function _photos_access_userlist in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 photos_access/photos_access.module \_photos_access_userlist()
- 8.4 photos_access/photos_access.module \_photos_access_userlist()
- 7.3 photos_access/photos_access.module \_photos_access_userlist()
List of users who have access to album.
2 calls to _photos_access_userlist()
- photos_access_form_node_form_alter in photos_access/
photos_access.module - Implements hook_form_BASE_FORM_ID_alter() for form_node.
- photos_access_node_load in photos_access/
photos_access.module - Implements hook_node_load().
File
- photos_access/
photos_access.module, line 836 - Implementation of photos_access.module.
Code
function _photos_access_userlist($id, $collaborate = FALSE) {
$db = \Drupal::database();
$results = $db
->query('SELECT u.uid, u.name FROM {users_field_data} u
INNER JOIN {photos_access_user} a ON u.uid = a.uid
WHERE a.id = :id AND a.collaborate = :collaborate', [
':id' => $id,
':collaborate' => $collaborate ? 1 : 0,
]);
$users = [];
foreach ($results as $result) {
$username = [
'#markup' => $result->name,
];
try {
$account = \Drupal::entityTypeManager()
->getStorage('user')
->load($result->uid);
$username = [
'#theme' => 'username',
'#account' => $account,
];
} catch (InvalidPluginDefinitionException $e) {
watchdog_exception('photos_access', $e);
} catch (PluginNotFoundException $e) {
watchdog_exception('photos_access', $e);
}
$users[] = [
'target_id' => $result->uid,
'name' => $result->name,
'username' => $username,
];
}
return $users;
}