UserViewsData.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. namespace Drupal\user;
  3. use Drupal\views\EntityViewsData;
  4. /**
  5. * Provides the views data for the user entity type.
  6. */
  7. class UserViewsData extends EntityViewsData {
  8. /**
  9. * {@inheritdoc}
  10. */
  11. public function getViewsData() {
  12. $data = parent::getViewsData();
  13. $data['users_field_data']['table']['base']['help'] = $this->t('Users who have created accounts on your site.');
  14. $data['users_field_data']['table']['base']['access query tag'] = 'user_access';
  15. $data['users_field_data']['table']['wizard_id'] = 'user';
  16. $data['users_field_data']['uid']['argument']['id'] = 'user_uid';
  17. $data['users_field_data']['uid']['argument'] += [
  18. 'name table' => 'users_field_data',
  19. 'name field' => 'name',
  20. 'empty field name' => \Drupal::config('user.settings')->get('anonymous'),
  21. ];
  22. $data['users_field_data']['uid']['filter']['id'] = 'user_name';
  23. $data['users_field_data']['uid']['filter']['title'] = $this->t('Name (autocomplete)');
  24. $data['users_field_data']['uid']['filter']['help'] = $this->t('The user or author name. Uses an autocomplete widget to find a user name, the actual filter uses the resulting user ID.');
  25. $data['users_field_data']['uid']['relationship'] = [
  26. 'title' => $this->t('Content authored'),
  27. 'help' => $this->t('Relate content to the user who created it. This relationship will create one record for each content item created by the user.'),
  28. 'id' => 'standard',
  29. 'base' => 'node_field_data',
  30. 'base field' => 'uid',
  31. 'field' => 'uid',
  32. 'label' => $this->t('nodes'),
  33. ];
  34. $data['users_field_data']['uid_raw'] = [
  35. 'help' => $this->t('The raw numeric user ID.'),
  36. 'real field' => 'uid',
  37. 'filter' => [
  38. 'title' => $this->t('The user ID'),
  39. 'id' => 'numeric',
  40. ],
  41. ];
  42. $data['users_field_data']['uid_representative'] = [
  43. 'relationship' => [
  44. 'title' => $this->t('Representative node'),
  45. 'label' => $this->t('Representative node'),
  46. 'help' => $this->t('Obtains a single representative node for each user, according to a chosen sort criterion.'),
  47. 'id' => 'groupwise_max',
  48. 'relationship field' => 'uid',
  49. 'outer field' => 'users_field_data.uid',
  50. 'argument table' => 'users_field_data',
  51. 'argument field' => 'uid',
  52. 'base' => 'node_field_data',
  53. 'field' => 'nid',
  54. 'relationship' => 'node_field_data:uid'
  55. ],
  56. ];
  57. $data['users']['uid_current'] = [
  58. 'real field' => 'uid',
  59. 'title' => $this->t('Current'),
  60. 'help' => $this->t('Filter the view to the currently logged in user.'),
  61. 'filter' => [
  62. 'id' => 'user_current',
  63. 'type' => 'yes-no',
  64. ],
  65. ];
  66. $data['users_field_data']['name']['help'] = $this->t('The user or author name.');
  67. $data['users_field_data']['name']['field']['default_formatter'] = 'user_name';
  68. $data['users_field_data']['name']['filter']['title'] = $this->t('Name (raw)');
  69. $data['users_field_data']['name']['filter']['help'] = $this->t('The user or author name. This filter does not check if the user exists and allows partial matching. Does not use autocomplete.');
  70. // Note that this field implements field level access control.
  71. $data['users_field_data']['mail']['help'] = $this->t('Email address for a given user. This field is normally not shown to users, so be cautious when using it.');
  72. $data['users_field_data']['langcode']['help'] = $this->t('Original language of the user information');
  73. $data['users_field_data']['langcode']['help'] = $this->t('Language of the translation of user information');
  74. $data['users_field_data']['preferred_langcode']['title'] = $this->t('Preferred language');
  75. $data['users_field_data']['preferred_langcode']['help'] = $this->t('Preferred language of the user');
  76. $data['users_field_data']['preferred_admin_langcode']['title'] = $this->t('Preferred admin language');
  77. $data['users_field_data']['preferred_admin_langcode']['help'] = $this->t('Preferred administrative language of the user');
  78. $data['users_field_data']['created_fulldate'] = [
  79. 'title' => $this->t('Created date'),
  80. 'help' => $this->t('Date in the form of CCYYMMDD.'),
  81. 'argument' => [
  82. 'field' => 'created',
  83. 'id' => 'date_fulldate',
  84. ],
  85. ];
  86. $data['users_field_data']['created_year_month'] = [
  87. 'title' => $this->t('Created year + month'),
  88. 'help' => $this->t('Date in the form of YYYYMM.'),
  89. 'argument' => [
  90. 'field' => 'created',
  91. 'id' => 'date_year_month',
  92. ],
  93. ];
  94. $data['users_field_data']['created_year'] = [
  95. 'title' => $this->t('Created year'),
  96. 'help' => $this->t('Date in the form of YYYY.'),
  97. 'argument' => [
  98. 'field' => 'created',
  99. 'id' => 'date_year',
  100. ],
  101. ];
  102. $data['users_field_data']['created_month'] = [
  103. 'title' => $this->t('Created month'),
  104. 'help' => $this->t('Date in the form of MM (01 - 12).'),
  105. 'argument' => [
  106. 'field' => 'created',
  107. 'id' => 'date_month',
  108. ],
  109. ];
  110. $data['users_field_data']['created_day'] = [
  111. 'title' => $this->t('Created day'),
  112. 'help' => $this->t('Date in the form of DD (01 - 31).'),
  113. 'argument' => [
  114. 'field' => 'created',
  115. 'id' => 'date_day',
  116. ],
  117. ];
  118. $data['users_field_data']['created_week'] = [
  119. 'title' => $this->t('Created week'),
  120. 'help' => $this->t('Date in the form of WW (01 - 53).'),
  121. 'argument' => [
  122. 'field' => 'created',
  123. 'id' => 'date_week',
  124. ],
  125. ];
  126. $data['users_field_data']['status']['filter']['label'] = $this->t('Active');
  127. $data['users_field_data']['status']['filter']['type'] = 'yes-no';
  128. $data['users_field_data']['changed']['title'] = $this->t('Updated date');
  129. $data['users_field_data']['changed_fulldate'] = [
  130. 'title' => $this->t('Updated date'),
  131. 'help' => $this->t('Date in the form of CCYYMMDD.'),
  132. 'argument' => [
  133. 'field' => 'changed',
  134. 'id' => 'date_fulldate',
  135. ],
  136. ];
  137. $data['users_field_data']['changed_year_month'] = [
  138. 'title' => $this->t('Updated year + month'),
  139. 'help' => $this->t('Date in the form of YYYYMM.'),
  140. 'argument' => [
  141. 'field' => 'changed',
  142. 'id' => 'date_year_month',
  143. ],
  144. ];
  145. $data['users_field_data']['changed_year'] = [
  146. 'title' => $this->t('Updated year'),
  147. 'help' => $this->t('Date in the form of YYYY.'),
  148. 'argument' => [
  149. 'field' => 'changed',
  150. 'id' => 'date_year',
  151. ],
  152. ];
  153. $data['users_field_data']['changed_month'] = [
  154. 'title' => $this->t('Updated month'),
  155. 'help' => $this->t('Date in the form of MM (01 - 12).'),
  156. 'argument' => [
  157. 'field' => 'changed',
  158. 'id' => 'date_month',
  159. ],
  160. ];
  161. $data['users_field_data']['changed_day'] = [
  162. 'title' => $this->t('Updated day'),
  163. 'help' => $this->t('Date in the form of DD (01 - 31).'),
  164. 'argument' => [
  165. 'field' => 'changed',
  166. 'id' => 'date_day',
  167. ],
  168. ];
  169. $data['users_field_data']['changed_week'] = [
  170. 'title' => $this->t('Updated week'),
  171. 'help' => $this->t('Date in the form of WW (01 - 53).'),
  172. 'argument' => [
  173. 'field' => 'changed',
  174. 'id' => 'date_week',
  175. ],
  176. ];
  177. $data['users']['data'] = [
  178. 'title' => $this->t('Data'),
  179. 'help' => $this->t('Provides access to the user data service.'),
  180. 'real field' => 'uid',
  181. 'field' => [
  182. 'id' => 'user_data',
  183. ],
  184. ];
  185. $data['users']['user_bulk_form'] = [
  186. 'title' => $this->t('Bulk update'),
  187. 'help' => $this->t('Add a form element that lets you run operations on multiple users.'),
  188. 'field' => [
  189. 'id' => 'user_bulk_form',
  190. ],
  191. ];
  192. // Alter the user roles target_id column.
  193. $data['user__roles']['roles_target_id']['field']['id'] = 'user_roles';
  194. $data['user__roles']['roles_target_id']['field']['no group by'] = TRUE;
  195. $data['user__roles']['roles_target_id']['filter']['id'] = 'user_roles';
  196. $data['user__roles']['roles_target_id']['filter']['allow empty'] = TRUE;
  197. $data['user__roles']['roles_target_id']['argument'] = [
  198. 'id' => 'user__roles_rid',
  199. 'name table' => 'role',
  200. 'name field' => 'name',
  201. 'empty field name' => $this->t('No role'),
  202. 'zero is null' => TRUE,
  203. 'numeric' => TRUE,
  204. ];
  205. $data['user__roles']['permission'] = [
  206. 'title' => $this->t('Permission'),
  207. 'help' => $this->t('The user permissions.'),
  208. 'field' => [
  209. 'id' => 'user_permissions',
  210. 'no group by' => TRUE,
  211. ],
  212. 'filter' => [
  213. 'id' => 'user_permissions',
  214. 'real field' => 'roles_target_id',
  215. ],
  216. ];
  217. return $data;
  218. }
  219. }