Pull merge.
[yaffs-website] / web / core / modules / node / src / NodeViewsData.php
1 <?php
2
3 namespace Drupal\node;
4
5 use Drupal\views\EntityViewsData;
6
7 /**
8  * Provides the views data for the node entity type.
9  */
10 class NodeViewsData extends EntityViewsData {
11
12   /**
13    * {@inheritdoc}
14    */
15   public function getViewsData() {
16     $data = parent::getViewsData();
17
18     $data['node_field_data']['table']['base']['weight'] = -10;
19     $data['node_field_data']['table']['base']['access query tag'] = 'node_access';
20     $data['node_field_data']['table']['wizard_id'] = 'node';
21
22     $data['node_field_data']['nid']['argument'] = [
23       'id' => 'node_nid',
24       'name field' => 'title',
25       'numeric' => TRUE,
26       'validate type' => 'nid',
27     ];
28
29     $data['node_field_data']['title']['field']['default_formatter_settings'] = ['link_to_entity' => TRUE];
30
31     $data['node_field_data']['title']['field']['link_to_node default'] = TRUE;
32
33     $data['node_field_data']['type']['argument']['id'] = 'node_type';
34
35     $data['node_field_data']['langcode']['help'] = $this->t('The language of the content or translation.');
36
37     $data['node_field_data']['status']['filter']['label'] = $this->t('Published status');
38     $data['node_field_data']['status']['filter']['type'] = 'yes-no';
39     // Use status = 1 instead of status <> 0 in WHERE statement.
40     $data['node_field_data']['status']['filter']['use_equal'] = TRUE;
41
42     $data['node_field_data']['status_extra'] = [
43       'title' => $this->t('Published status or admin user'),
44       'help' => $this->t('Filters out unpublished content if the current user cannot view it.'),
45       'filter' => [
46         'field' => 'status',
47         'id' => 'node_status',
48         'label' => $this->t('Published status or admin user'),
49       ],
50     ];
51
52     $data['node_field_data']['promote']['help'] = $this->t('A boolean indicating whether the node is visible on the front page.');
53     $data['node_field_data']['promote']['filter']['label'] = $this->t('Promoted to front page status');
54     $data['node_field_data']['promote']['filter']['type'] = 'yes-no';
55
56     $data['node_field_data']['sticky']['help'] = $this->t('A boolean indicating whether the node should sort to the top of content lists.');
57     $data['node_field_data']['sticky']['filter']['label'] = $this->t('Sticky status');
58     $data['node_field_data']['sticky']['filter']['type'] = 'yes-no';
59     $data['node_field_data']['sticky']['sort']['help'] = $this->t('Whether or not the content is sticky. To list sticky content first, set this to descending.');
60
61     $data['node']['node_bulk_form'] = [
62       'title' => $this->t('Node operations bulk form'),
63       'help' => $this->t('Add a form element that lets you run operations on multiple nodes.'),
64       'field' => [
65         'id' => 'node_bulk_form',
66       ],
67     ];
68
69     // Bogus fields for aliasing purposes.
70
71     // @todo Add similar support to any date field
72     // @see https://www.drupal.org/node/2337507
73     $data['node_field_data']['created_fulldate'] = [
74       'title' => $this->t('Created date'),
75       'help' => $this->t('Date in the form of CCYYMMDD.'),
76       'argument' => [
77         'field' => 'created',
78         'id' => 'date_fulldate',
79       ],
80     ];
81
82     $data['node_field_data']['created_year_month'] = [
83       'title' => $this->t('Created year + month'),
84       'help' => $this->t('Date in the form of YYYYMM.'),
85       'argument' => [
86         'field' => 'created',
87         'id' => 'date_year_month',
88       ],
89     ];
90
91     $data['node_field_data']['created_year'] = [
92       'title' => $this->t('Created year'),
93       'help' => $this->t('Date in the form of YYYY.'),
94       'argument' => [
95         'field' => 'created',
96         'id' => 'date_year',
97       ],
98     ];
99
100     $data['node_field_data']['created_month'] = [
101       'title' => $this->t('Created month'),
102       'help' => $this->t('Date in the form of MM (01 - 12).'),
103       'argument' => [
104         'field' => 'created',
105         'id' => 'date_month',
106       ],
107     ];
108
109     $data['node_field_data']['created_day'] = [
110       'title' => $this->t('Created day'),
111       'help' => $this->t('Date in the form of DD (01 - 31).'),
112       'argument' => [
113         'field' => 'created',
114         'id' => 'date_day',
115       ],
116     ];
117
118     $data['node_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
127     $data['node_field_data']['changed_fulldate'] = [
128       'title' => $this->t('Updated date'),
129       'help' => $this->t('Date in the form of CCYYMMDD.'),
130       'argument' => [
131         'field' => 'changed',
132         'id' => 'date_fulldate',
133       ],
134     ];
135
136     $data['node_field_data']['changed_year_month'] = [
137       'title' => $this->t('Updated year + month'),
138       'help' => $this->t('Date in the form of YYYYMM.'),
139       'argument' => [
140         'field' => 'changed',
141         'id' => 'date_year_month',
142       ],
143     ];
144
145     $data['node_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
154     $data['node_field_data']['changed_month'] = [
155       'title' => $this->t('Updated month'),
156       'help' => $this->t('Date in the form of MM (01 - 12).'),
157       'argument' => [
158         'field' => 'changed',
159         'id' => 'date_month',
160       ],
161     ];
162
163     $data['node_field_data']['changed_day'] = [
164       'title' => $this->t('Updated day'),
165       'help' => $this->t('Date in the form of DD (01 - 31).'),
166       'argument' => [
167         'field' => 'changed',
168         'id' => 'date_day',
169       ],
170     ];
171
172     $data['node_field_data']['changed_week'] = [
173       'title' => $this->t('Updated week'),
174       'help' => $this->t('Date in the form of WW (01 - 53).'),
175       'argument' => [
176         'field' => 'changed',
177         'id' => 'date_week',
178       ],
179     ];
180
181     $data['node_field_data']['uid']['help'] = $this->t('The user authoring the content. If you need more fields than the uid add the content: author relationship');
182     $data['node_field_data']['uid']['filter']['id'] = 'user_name';
183     $data['node_field_data']['uid']['relationship']['title'] = $this->t('Content author');
184     $data['node_field_data']['uid']['relationship']['help'] = $this->t('Relate content to the user who created it.');
185     $data['node_field_data']['uid']['relationship']['label'] = $this->t('author');
186
187     $data['node']['node_listing_empty'] = [
188       'title' => $this->t('Empty Node Frontpage behavior'),
189       'help' => $this->t('Provides a link to the node add overview page.'),
190       'area' => [
191         'id' => 'node_listing_empty',
192       ],
193     ];
194
195     $data['node_field_data']['uid_revision']['title'] = $this->t('User has a revision');
196     $data['node_field_data']['uid_revision']['help'] = $this->t('All nodes where a certain user has a revision');
197     $data['node_field_data']['uid_revision']['real field'] = 'nid';
198     $data['node_field_data']['uid_revision']['filter']['id'] = 'node_uid_revision';
199     $data['node_field_data']['uid_revision']['argument']['id'] = 'node_uid_revision';
200
201     $data['node_field_revision']['table']['wizard_id'] = 'node_revision';
202
203     // Advertise this table as a possible base table.
204     $data['node_field_revision']['table']['base']['help'] = $this->t('Content revision is a history of changes to content.');
205     $data['node_field_revision']['table']['base']['defaults']['title'] = 'title';
206
207     $data['node_field_revision']['nid']['argument'] = [
208       'id' => 'node_nid',
209       'numeric' => TRUE,
210     ];
211     // @todo the NID field needs different behaviour on revision/non-revision
212     //   tables. It would be neat if this could be encoded in the base field
213     //   definition.
214     $data['node_field_revision']['nid']['relationship']['id'] = 'standard';
215     $data['node_field_revision']['nid']['relationship']['base'] = 'node_field_data';
216     $data['node_field_revision']['nid']['relationship']['base field'] = 'nid';
217     $data['node_field_revision']['nid']['relationship']['title'] = $this->t('Content');
218     $data['node_field_revision']['nid']['relationship']['label'] = $this->t('Get the actual content from a content revision.');
219     $data['node_field_revision']['nid']['relationship']['extra'][] = [
220       'field' => 'langcode',
221       'left_field' => 'langcode',
222     ];
223
224     $data['node_field_revision']['vid'] = [
225       'argument' => [
226         'id' => 'node_vid',
227         'numeric' => TRUE,
228       ],
229       'relationship' => [
230         'id' => 'standard',
231         'base' => 'node_field_data',
232         'base field' => 'vid',
233         'title' => $this->t('Content'),
234         'label' => $this->t('Get the actual content from a content revision.'),
235         'extra' => [
236           [
237             'field' => 'langcode',
238             'left_field' => 'langcode',
239           ],
240         ],
241       ],
242     ] + $data['node_field_revision']['vid'];
243
244     $data['node_field_revision']['langcode']['help'] = $this->t('The language the original content is in.');
245
246     $data['node_revision']['revision_uid']['help'] = $this->t('Relate a content revision to the user who created the revision.');
247     $data['node_revision']['revision_uid']['relationship']['label'] = $this->t('revision user');
248
249     $data['node_field_revision']['table']['wizard_id'] = 'node_field_revision';
250
251     $data['node_field_revision']['table']['join']['node_field_data']['left_field'] = 'vid';
252     $data['node_field_revision']['table']['join']['node_field_data']['field'] = 'vid';
253
254     $data['node_field_revision']['status']['filter']['label'] = $this->t('Published');
255     $data['node_field_revision']['status']['filter']['type'] = 'yes-no';
256     $data['node_field_revision']['status']['filter']['use_equal'] = TRUE;
257
258     $data['node_field_revision']['promote']['help'] = $this->t('A boolean indicating whether the node is visible on the front page.');
259
260     $data['node_field_revision']['sticky']['help'] = $this->t('A boolean indicating whether the node should sort to the top of content lists.');
261
262     $data['node_field_revision']['langcode']['help'] = $this->t('The language of the content or translation.');
263
264     $data['node_field_revision']['link_to_revision'] = [
265       'field' => [
266         'title' => $this->t('Link to revision'),
267         'help' => $this->t('Provide a simple link to the revision.'),
268         'id' => 'node_revision_link',
269         'click sortable' => FALSE,
270       ],
271     ];
272
273     $data['node_field_revision']['revert_revision'] = [
274       'field' => [
275         'title' => $this->t('Link to revert revision'),
276         'help' => $this->t('Provide a simple link to revert to the revision.'),
277         'id' => 'node_revision_link_revert',
278         'click sortable' => FALSE,
279       ],
280     ];
281
282     $data['node_field_revision']['delete_revision'] = [
283       'field' => [
284         'title' => $this->t('Link to delete revision'),
285         'help' => $this->t('Provide a simple link to delete the content revision.'),
286         'id' => 'node_revision_link_delete',
287         'click sortable' => FALSE,
288       ],
289     ];
290
291     // Define the base group of this table. Fields that don't have a group defined
292     // will go into this field by default.
293     $data['node_access']['table']['group'] = $this->t('Content access');
294
295     // For other base tables, explain how we join.
296     $data['node_access']['table']['join'] = [
297       'node_field_data' => [
298         'left_field' => 'nid',
299         'field' => 'nid',
300       ],
301     ];
302     $data['node_access']['nid'] = [
303       'title' => $this->t('Access'),
304       'help' => $this->t('Filter by access.'),
305       'filter' => [
306         'id' => 'node_access',
307         'help' => $this->t('Filter for content by view access. <strong>Not necessary if you are using node as your base table.</strong>'),
308       ],
309     ];
310
311     // Add search table, fields, filters, etc., but only if a page using the
312     // node_search plugin is enabled.
313     if (\Drupal::moduleHandler()->moduleExists('search')) {
314       $enabled = FALSE;
315       $search_page_repository = \Drupal::service('search.search_page_repository');
316       foreach ($search_page_repository->getActiveSearchpages() as $page) {
317         if ($page->getPlugin()->getPluginId() == 'node_search') {
318           $enabled = TRUE;
319           break;
320         }
321       }
322
323       if ($enabled) {
324         $data['node_search_index']['table']['group'] = $this->t('Search');
325
326         // Automatically join to the node table (or actually, node_field_data).
327         // Use a Views table alias to allow other modules to use this table too,
328         // if they use the search index.
329         $data['node_search_index']['table']['join'] = [
330           'node_field_data' => [
331             'left_field' => 'nid',
332             'field' => 'sid',
333             'table' => 'search_index',
334             'extra' => "node_search_index.type = 'node_search' AND node_search_index.langcode = node_field_data.langcode",
335           ],
336         ];
337
338         $data['node_search_total']['table']['join'] = [
339           'node_search_index' => [
340             'left_field' => 'word',
341             'field' => 'word',
342           ],
343         ];
344
345         $data['node_search_dataset']['table']['join'] = [
346           'node_field_data' => [
347             'left_field' => 'sid',
348             'left_table' => 'node_search_index',
349             'field' => 'sid',
350             'table' => 'search_dataset',
351             'extra' => 'node_search_index.type = node_search_dataset.type AND node_search_index.langcode = node_search_dataset.langcode',
352             'type' => 'INNER',
353           ],
354         ];
355
356         $data['node_search_index']['score'] = [
357           'title' => $this->t('Score'),
358           'help' => $this->t('The score of the search item. This will not be used if the search filter is not also present.'),
359           'field' => [
360             'id' => 'search_score',
361             'float' => TRUE,
362             'no group by' => TRUE,
363           ],
364           'sort' => [
365             'id' => 'search_score',
366             'no group by' => TRUE,
367           ],
368         ];
369
370         $data['node_search_index']['keys'] = [
371           'title' => $this->t('Search Keywords'),
372           'help' => $this->t('The keywords to search for.'),
373           'filter' => [
374             'id' => 'search_keywords',
375             'no group by' => TRUE,
376             'search_type' => 'node_search',
377           ],
378           'argument' => [
379             'id' => 'search',
380             'no group by' => TRUE,
381             'search_type' => 'node_search',
382           ],
383         ];
384
385       }
386     }
387
388     return $data;
389   }
390
391 }