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