Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[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
220     $data['node_field_revision']['vid'] = [
221       'argument' => [
222         'id' => 'node_vid',
223         'numeric' => TRUE,
224       ],
225       'relationship' => [
226         'id' => 'standard',
227         'base' => 'node_field_data',
228         'base field' => 'vid',
229         'title' => $this->t('Content'),
230         'label' => $this->t('Get the actual content from a content revision.'),
231       ],
232     ] + $data['node_field_revision']['vid'];
233
234     $data['node_field_revision']['langcode']['help'] = $this->t('The language the original content is in.');
235
236     $data['node_revision']['revision_uid']['help'] = $this->t('Relate a content revision to the user who created the revision.');
237     $data['node_revision']['revision_uid']['relationship']['label'] = $this->t('revision user');
238
239     $data['node_field_revision']['table']['wizard_id'] = 'node_field_revision';
240
241     $data['node_field_revision']['table']['join']['node_field_data']['left_field'] = 'vid';
242     $data['node_field_revision']['table']['join']['node_field_data']['field'] = 'vid';
243
244     $data['node_field_revision']['status']['filter']['label'] = $this->t('Published');
245     $data['node_field_revision']['status']['filter']['type'] = 'yes-no';
246     $data['node_field_revision']['status']['filter']['use_equal'] = TRUE;
247
248     $data['node_field_revision']['promote']['help'] = $this->t('A boolean indicating whether the node is visible on the front page.');
249
250     $data['node_field_revision']['sticky']['help'] = $this->t('A boolean indicating whether the node should sort to the top of content lists.');
251
252     $data['node_field_revision']['langcode']['help'] = $this->t('The language of the content or translation.');
253
254     $data['node_field_revision']['link_to_revision'] = [
255       'field' => [
256         'title' => $this->t('Link to revision'),
257         'help' => $this->t('Provide a simple link to the revision.'),
258         'id' => 'node_revision_link',
259         'click sortable' => FALSE,
260       ],
261     ];
262
263     $data['node_field_revision']['revert_revision'] = [
264       'field' => [
265         'title' => $this->t('Link to revert revision'),
266         'help' => $this->t('Provide a simple link to revert to the revision.'),
267         'id' => 'node_revision_link_revert',
268         'click sortable' => FALSE,
269       ],
270     ];
271
272     $data['node_field_revision']['delete_revision'] = [
273       'field' => [
274         'title' => $this->t('Link to delete revision'),
275         'help' => $this->t('Provide a simple link to delete the content revision.'),
276         'id' => 'node_revision_link_delete',
277         'click sortable' => FALSE,
278       ],
279     ];
280
281     // Define the base group of this table. Fields that don't have a group defined
282     // will go into this field by default.
283     $data['node_access']['table']['group'] = $this->t('Content access');
284
285     // For other base tables, explain how we join.
286     $data['node_access']['table']['join'] = [
287       'node_field_data' => [
288         'left_field' => 'nid',
289         'field' => 'nid',
290       ],
291     ];
292     $data['node_access']['nid'] = [
293       'title' => $this->t('Access'),
294       'help' => $this->t('Filter by access.'),
295       'filter' => [
296         'id' => 'node_access',
297         'help' => $this->t('Filter for content by view access. <strong>Not necessary if you are using node as your base table.</strong>'),
298       ],
299     ];
300
301     // Add search table, fields, filters, etc., but only if a page using the
302     // node_search plugin is enabled.
303     if (\Drupal::moduleHandler()->moduleExists('search')) {
304       $enabled = FALSE;
305       $search_page_repository = \Drupal::service('search.search_page_repository');
306       foreach ($search_page_repository->getActiveSearchpages() as $page) {
307         if ($page->getPlugin()->getPluginId() == 'node_search') {
308           $enabled = TRUE;
309           break;
310         }
311       }
312
313       if ($enabled) {
314         $data['node_search_index']['table']['group'] = $this->t('Search');
315
316         // Automatically join to the node table (or actually, node_field_data).
317         // Use a Views table alias to allow other modules to use this table too,
318         // if they use the search index.
319         $data['node_search_index']['table']['join'] = [
320           'node_field_data' => [
321             'left_field' => 'nid',
322             'field' => 'sid',
323             'table' => 'search_index',
324             'extra' => "node_search_index.type = 'node_search' AND node_search_index.langcode = node_field_data.langcode",
325           ],
326         ];
327
328         $data['node_search_total']['table']['join'] = [
329           'node_search_index' => [
330             'left_field' => 'word',
331             'field' => 'word',
332           ],
333         ];
334
335         $data['node_search_dataset']['table']['join'] = [
336           'node_field_data' => [
337             'left_field' => 'sid',
338             'left_table' => 'node_search_index',
339             'field' => 'sid',
340             'table' => 'search_dataset',
341             'extra' => 'node_search_index.type = node_search_dataset.type AND node_search_index.langcode = node_search_dataset.langcode',
342             'type' => 'INNER',
343           ],
344         ];
345
346         $data['node_search_index']['score'] = [
347           'title' => $this->t('Score'),
348           'help' => $this->t('The score of the search item. This will not be used if the search filter is not also present.'),
349           'field' => [
350             'id' => 'search_score',
351             'float' => TRUE,
352             'no group by' => TRUE,
353           ],
354           'sort' => [
355             'id' => 'search_score',
356             'no group by' => TRUE,
357           ],
358         ];
359
360         $data['node_search_index']['keys'] = [
361           'title' => $this->t('Search Keywords'),
362           'help' => $this->t('The keywords to search for.'),
363           'filter' => [
364             'id' => 'search_keywords',
365             'no group by' => TRUE,
366             'search_type' => 'node_search',
367           ],
368           'argument' => [
369             'id' => 'search',
370             'no group by' => TRUE,
371             'search_type' => 'node_search',
372           ],
373         ];
374
375       }
376     }
377
378     return $data;
379   }
380
381 }