Skip to content
user.views.inc 11.3 KiB
Newer Older
Earl Miles's avatar
Earl Miles committed
<?php

/**
 * @file
Earl Miles's avatar
Earl Miles committed
/**
 * Implements hook_views_data().
 */
function user_views_data() {

  // Define the base group of this table. Fields that don't have a group defined
  // will go into this field by default.
Earl Miles's avatar
Earl Miles committed
  $data['users']['table']['group']  = t('User');

  $data['users']['table']['base'] = array(
    'field' => 'uid',
    'title' => t('User'),
    'help' => t('Users who have created accounts on your site.'),
    'access query tag' => 'user_access',
  );
  $data['users']['table']['entity type'] = 'user';
  $data['users']['table']['wizard_id'] = 'user';
Earl Miles's avatar
Earl Miles committed

  $data['users']['uid'] = array(
    'title' => t('Uid'),
Earl Miles's avatar
Earl Miles committed
    'field' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user',
Earl Miles's avatar
Earl Miles committed
    ),
    'argument' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_uid',
      'empty field name' => \Drupal::config('user.settings')->get('anonymous'),
Earl Miles's avatar
Earl Miles committed
    ),
    'filter' => array(
      'title' => t('Name'),
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_name',
Earl Miles's avatar
Earl Miles committed
    ),
    'sort' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'standard',
Earl Miles's avatar
Earl Miles committed
    ),
    'relationship' => array(
      'title' => t('Content authored'),
      'help' => t('Relate content to the user who created it. This relationship will create one record for each content item created by the user.'),
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'standard',
Earl Miles's avatar
Earl Miles committed
      'base field' => 'uid',
      'field' => 'uid',
      'label' => t('nodes'),
    ),
  );

  $data['users']['uid_raw'] = array(
    'help' => t('The raw numeric user ID.'),
    'real field' => 'uid',
    'filter' => array(
      'title' => t('The user ID'),
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'numeric',
Earl Miles's avatar
Earl Miles committed
  $data['users']['uid_representative'] = array(
    'relationship' => array(
      'title' => t('Representative node'),
      'label'  => t('Representative node'),
      'help' => t('Obtains a single representative node for each user, according to a chosen sort criterion.'),
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'groupwise_max',
Earl Miles's avatar
Earl Miles committed
      'relationship field' => 'uid',
      'outer field' => 'users.uid',
      'argument table' => 'users',
      'argument field' => 'uid',
      'base' => 'node',
      'field' => 'nid',
      'relationship' => 'node_field_data:uid'
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['uid_current'] = array(
    'real field' => 'uid',
    'title' => t('Current'),
    'help' => t('Filter the view to the currently logged in user.'),
    'filter' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_current',
Earl Miles's avatar
Earl Miles committed
      'type' => 'yes-no',
    ),
  );

  $data['users']['name'] = array(
    'title' => t('Name'),
    'help' => t('The user or author name.'),
Earl Miles's avatar
Earl Miles committed
    'field' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_name',
Earl Miles's avatar
Earl Miles committed
    ),
    'sort' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'standard',
Earl Miles's avatar
Earl Miles committed
    ),
    'argument' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'string',
Earl Miles's avatar
Earl Miles committed
    ),
    'filter' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'string',
Earl Miles's avatar
Earl Miles committed
      'title' => t('Name (raw)'),
      'help' => t('The user or author name. This filter does not check if the user exists and allows partial matching. Does not utilize autocomplete.')
    ),
  );

  // Note that this field implements field level access control.
  $data['users']['mail'] = array(
    'title' => t('Email'),
    'help' => t('Email address for a given user. This field is normally not shown to users, so be cautious when using it.'),
Earl Miles's avatar
Earl Miles committed
    'field' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_mail',
Earl Miles's avatar
Earl Miles committed
    ),
    'sort' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'standard',
Earl Miles's avatar
Earl Miles committed
    ),
    'filter' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'string',
Earl Miles's avatar
Earl Miles committed
    ),
    'argument' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'string',
Earl Miles's avatar
Earl Miles committed
    'help' => t('Language of the user'),
    'field' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_language',
Earl Miles's avatar
Earl Miles committed
    ),
    'sort' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'standard',
Earl Miles's avatar
Earl Miles committed
    ),
    'filter' => array(
Earl Miles's avatar
Earl Miles committed
    ),
    'argument' => array(
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['view_user'] = array(
    'field' => array(
Earl Miles's avatar
Earl Miles committed
      'help' => t('Provide a simple link to the user.'),
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_link',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['created'] = array(
    'title' => t('Created date'),
    'help' => t('The date the user was created.'),
Earl Miles's avatar
Earl Miles committed
    'field' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'date',
Earl Miles's avatar
Earl Miles committed
    ),
    'sort' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'date'
Earl Miles's avatar
Earl Miles committed
    ),
    'filter' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'date',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['created_fulldate'] = array(
    'title' => t('Created date'),
    'help' => t('Date in the form of CCYYMMDD.'),
    'argument' => array(
      'field' => 'created',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['created_year_month'] = array(
    'title' => t('Created year + month'),
    'help' => t('Date in the form of YYYYMM.'),
    'argument' => array(
      'field' => 'created',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['created_year'] = array(
    'title' => t('Created year'),
    'help' => t('Date in the form of YYYY.'),
    'argument' => array(
      'field' => 'created',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['created_month'] = array(
    'title' => t('Created month'),
    'help' => t('Date in the form of MM (01 - 12).'),
    'argument' => array(
      'field' => 'created',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['created_day'] = array(
    'title' => t('Created day'),
    'help' => t('Date in the form of DD (01 - 31).'),
    'argument' => array(
      'field' => 'created',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['created_week'] = array(
    'title' => t('Created week'),
    'help' => t('Date in the form of WW (01 - 53).'),
    'argument' => array(
      'field' => 'created',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['access'] = array(
    'title' => t('Last access'),
    'help' => t("The user's last access date."),
Earl Miles's avatar
Earl Miles committed
    'field' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'date',
Earl Miles's avatar
Earl Miles committed
    ),
    'sort' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'date'
Earl Miles's avatar
Earl Miles committed
    ),
    'filter' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'date',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['login'] = array(
    'title' => t('Last login'),
    'help' => t("The user's last login date."),
Earl Miles's avatar
Earl Miles committed
    'field' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'date',
Earl Miles's avatar
Earl Miles committed
    ),
    'sort' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'date'
Earl Miles's avatar
Earl Miles committed
    ),
    'filter' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'date',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['status'] = array(
    'help' => t('Whether a user is active or blocked.'),
Earl Miles's avatar
Earl Miles committed
    'field' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'boolean',
Earl Miles's avatar
Earl Miles committed
      'output formats' => array(
        'active-blocked' => array(t('Active'), t('Blocked')),
      ),
    ),
    'filter' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'boolean',
Earl Miles's avatar
Earl Miles committed
      'label' => t('Active'),
      'type' => 'yes-no',
    ),
    'sort' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'standard',
  $data['users']['changed'] = array(
    'title' => t('Updated date'),
    'help' => t('The date the user was last updated.'),
    'field' => array(
      'id' => 'date',
    ),
    'sort' => array(
      'id' => 'date'
    ),
    'filter' => array(
      'id' => 'date',
    ),
  );

  $data['users']['changed_fulldate'] = array(
    'title' => t('Updated date'),
    'help' => t('Date in the form of CCYYMMDD.'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_fulldate',
    ),
  );

  $data['users']['changed_year_month'] = array(
    'title' => t('Updated year + month'),
    'help' => t('Date in the form of YYYYMM.'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_year_month',
    ),
  );

  $data['users']['changed_year'] = array(
    'title' => t('Updated year'),
    'help' => t('Date in the form of YYYY.'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_year',
    ),
  );

  $data['users']['changed_month'] = array(
    'title' => t('Updated month'),
    'help' => t('Date in the form of MM (01 - 12).'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_month',
    ),
  );

  $data['users']['changed_day'] = array(
    'title' => t('Updated day'),
    'help' => t('Date in the form of DD (01 - 31).'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_day',
    ),
  );

  $data['users']['changed_week'] = array(
    'title' => t('Updated week'),
    'help' => t('Date in the form of WW (01 - 53).'),
    'argument' => array(
      'field' => 'changed',
      'id' => 'date_week',
    ),
  );

  if (\Drupal::moduleHandler()->moduleExists('filter')) {
    $data['users']['signature'] = array(
      'title' => t('Signature'),
      'help' => t("The user's signature."),
      'field' => array(
        'id' => 'markup',
        'format' => filter_fallback_format(),
        'click sortable' => FALSE,
      ),
      'filter' => array(
        'id' => 'string',
      ),
    );
  }
  if (\Drupal::moduleHandler()->moduleExists('content_translation')) {
    $data['users']['translation_link'] = array(
      'title' => t('Translation link'),
      'help' => t('Provide a link to the translations overview for users.'),
      'field' => array(
Earl Miles's avatar
Earl Miles committed
  $data['users']['edit_node'] = array(
    'field' => array(
Earl Miles's avatar
Earl Miles committed
      'help' => t('Provide a simple link to edit the user.'),
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_link_edit',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  $data['users']['cancel_node'] = array(
    'field' => array(
Earl Miles's avatar
Earl Miles committed
      'help' => t('Provide a simple link to cancel the user.'),
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_link_cancel',
  $data['users']['data'] = array(
    'title' => t('Data'),
    'help' => t('Provides access to the user data service.'),
    'real field' => 'uid',
    'field' => array(
      'id' => 'user_data',
    ),
  );

  // Define the base group of this table. Fields that don't have a group defined
  // will go into this field by default.
Earl Miles's avatar
Earl Miles committed
  $data['users_roles']['table']['group']  = t('User');

  // Explain how this table joins to others.
  $data['users_roles']['table']['join'] = array(
    'users' => array(
      'left_field' => 'uid',
      'field' => 'uid',
    ),
  );

  $data['users_roles']['rid'] = array(
    'title' => t('Roles'),
    'help' => t('Roles that a user belongs to.'),
    'field' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_roles',
Earl Miles's avatar
Earl Miles committed
      'no group by' => TRUE,
    ),
    'filter' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_roles',
Earl Miles's avatar
Earl Miles committed
      'allow empty' => TRUE,
    ),
    'argument' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'users_roles_rid',
Earl Miles's avatar
Earl Miles committed
      'name table' => 'role',
      'name field' => 'name',
      'empty field name' => t('No role'),
      'zero is null' => TRUE,
      'numeric' => TRUE,
    ),
  );

  $data['users_roles']['permission'] = array(
Earl Miles's avatar
Earl Miles committed
    'title' => t('Permission'),
    'help' => t('The user permissions.'),
    'field' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_permissions',
Earl Miles's avatar
Earl Miles committed
      'no group by' => TRUE,
    ),
    'filter' => array(
Bram Goffings's avatar
Bram Goffings committed
      'id' => 'user_permissions',
Earl Miles's avatar
Earl Miles committed
    ),
  );

  return $data;
}
/**
 * Implements hook_views_data_alter().
 */
function user_views_data_alter(&$data) {
  $data['users']['user_bulk_form'] = array(
    'title' => t('Bulk update'),
    'help' => t('Add a form element that lets you run operations on multiple users.'),
    'field' => array(
      'id' => 'user_bulk_form',
    ),
  );
}

/**
 * Implements hook_views_plugins_argument_validator_alter().
 */
function user_views_plugins_argument_validator_alter(array &$plugins) {
  $plugins['entity:user']['title'] = t('User ID');
  $plugins['entity:user']['class'] = 'Drupal\user\Plugin\views\argument_validator\User';
  $plugins['entity:user']['provider'] = 'user';
}