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