Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Ideally the user should be able to relate a view of users or any relationship providing a uid with the login_history table. For instance, if you have a view of users by username, why not add a field for user logins? Aggregating the count of this field would result in a field with total logins. This is only possible with a relationship.
/**
* Implements hook_views_data_alter().
*/
function login_history_utility_views_data_alter(array &$data)
{
$data['users']['login_history'] = [
'title' => t('Logins'),
'help' => t('Relate a user to historical logins'),
'relationship' => [
'id' => 'standard',
'group' => 'Login History',
'base' => 'login_history',
'base field' => 'uid',
'relationship field' => 'uid',
'handler' => 'standard',
'label' => t('Logins'),
'field' => 'uid'
],
];
}
Comment | File | Size | Author |
---|---|---|---|
#2 | Active Users User National Association of State Workforce Agencies.png | 186.02 KB | brooke_heaton |
#2 | add_views_relationship_handler_3092895_2.patch | 877 bytes | brooke_heaton |
Comments
Comment #2
brooke_heaton CreditAttribution: brooke_heaton commentedPatch adds a views handler. The result is that ability to join a user base table view with login_history, allowing for a view of users and user fields with their login history.
Comment #3
brooke_heaton CreditAttribution: brooke_heaton commentedComment #4
brooke_heaton CreditAttribution: brooke_heaton commentedSteps to test:
Add a view of users (base table === users)
Add a relationship to 'Logins' (Group === 'Login History')
Add a field for Logins (this will result in multiple rows - so use aggregation to count them if you want a total).
Profit
Comment #5
jcnventura CreditAttribution: jcnventura at 1xINTERNET commentedThe function name must be
login_history_views_data_alter
and notlogin_history_utility_views_data_alter
.Comment #7
jcnventura CreditAttribution: jcnventura at 1xINTERNET commented