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'
    ],
  ];
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

brooke_heaton created an issue. See original summary.

brooke_heaton’s picture

Patch 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.

Screenshot of view relationship widget showing a Login History relationship made possible with this patch.

brooke_heaton’s picture

Status: Needs work » Needs review
brooke_heaton’s picture

Steps 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

jcnventura’s picture

Status: Needs review » Needs work

The function name must be login_history_views_data_alter and not login_history_utility_views_data_alter.

  • jcnventura authored a2608e1 on 8.x-1.x
    Issue #3092895 by brooke_heaton, jcnventura: Add a views relationship...
jcnventura’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.