5 use Drupal\views\EntityViewsData;
8 * Provides the views data for the node entity type.
10 class NodeViewsData extends EntityViewsData {
15 public function getViewsData() {
16 $data = parent::getViewsData();
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';
22 $data['node_field_data']['nid']['argument'] = [
24 'name field' => 'title',
26 'validate type' => 'nid',
29 $data['node_field_data']['title']['field']['default_formatter_settings'] = ['link_to_entity' => TRUE];
31 $data['node_field_data']['title']['field']['link_to_node default'] = TRUE;
33 $data['node_field_data']['type']['argument']['id'] = 'node_type';
35 $data['node_field_data']['langcode']['help'] = $this->t('The language of the content or translation.');
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;
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.'),
47 'id' => 'node_status',
48 'label' => $this->t('Published status or admin user'),
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';
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.');
61 $data['node']['path'] = [
63 'title' => $this->t('Path'),
64 'help' => $this->t('The aliased path to this content.'),
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.'),
73 'id' => 'node_bulk_form',
77 // Bogus fields for aliasing purposes.
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.'),
86 'id' => 'date_fulldate',
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.'),
95 'id' => 'date_year_month',
99 $data['node_field_data']['created_year'] = [
100 'title' => $this->t('Created year'),
101 'help' => $this->t('Date in the form of YYYY.'),
103 'field' => 'created',
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).'),
112 'field' => 'created',
113 'id' => 'date_month',
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).'),
121 'field' => 'created',
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).'),
130 'field' => 'created',
135 $data['node_field_data']['changed_fulldate'] = [
136 'title' => $this->t('Updated date'),
137 'help' => $this->t('Date in the form of CCYYMMDD.'),
139 'field' => 'changed',
140 'id' => 'date_fulldate',
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.'),
148 'field' => 'changed',
149 'id' => 'date_year_month',
153 $data['node_field_data']['changed_year'] = [
154 'title' => $this->t('Updated year'),
155 'help' => $this->t('Date in the form of YYYY.'),
157 'field' => 'changed',
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).'),
166 'field' => 'changed',
167 'id' => 'date_month',
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).'),
175 'field' => 'changed',
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).'),
184 'field' => 'changed',
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');
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.'),
199 'id' => 'node_listing_empty',
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';
209 $data['node_field_revision']['table']['wizard_id'] = 'node_revision';
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';
215 $data['node_field_revision']['nid']['argument'] = [
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
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.');
228 $data['node_field_revision']['vid'] = [
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.'),
240 ] + $data['node_field_revision']['vid'];
242 $data['node_field_revision']['langcode']['help'] = $this->t('The language the original content is in.');
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');
247 $data['node_field_revision']['table']['wizard_id'] = 'node_field_revision';
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';
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;
256 $data['node_field_revision']['promote']['help'] = $this->t('A boolean indicating whether the node is visible on the front page.');
258 $data['node_field_revision']['sticky']['help'] = $this->t('A boolean indicating whether the node should sort to the top of content lists.');
260 $data['node_field_revision']['langcode']['help'] = $this->t('The language of the content or translation.');
262 $data['node_field_revision']['link_to_revision'] = [
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,
271 $data['node_field_revision']['revert_revision'] = [
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,
280 $data['node_field_revision']['delete_revision'] = [
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,
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');
293 // For other base tables, explain how we join.
294 $data['node_access']['table']['join'] = [
295 'node_field_data' => [
296 'left_field' => 'nid',
300 $data['node_access']['nid'] = [
301 'title' => $this->t('Access'),
302 'help' => $this->t('Filter by access.'),
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>'),
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')) {
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') {
322 $data['node_search_index']['table']['group'] = $this->t('Search');
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',
331 'table' => 'search_index',
332 'extra' => "node_search_index.type = 'node_search' AND node_search_index.langcode = node_field_data.langcode",
336 $data['node_search_total']['table']['join'] = [
337 'node_search_index' => [
338 'left_field' => 'word',
343 $data['node_search_dataset']['table']['join'] = [
344 'node_field_data' => [
345 'left_field' => 'sid',
346 'left_table' => 'node_search_index',
348 'table' => 'search_dataset',
349 'extra' => 'node_search_index.type = node_search_dataset.type AND node_search_index.langcode = node_search_dataset.langcode',
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.'),
358 'id' => 'search_score',
360 'no group by' => TRUE,
363 'id' => 'search_score',
364 'no group by' => TRUE,
368 $data['node_search_index']['keys'] = [
369 'title' => $this->t('Search Keywords'),
370 'help' => $this->t('The keywords to search for.'),
372 'id' => 'search_keywords',
373 'no group by' => TRUE,
374 'search_type' => 'node_search',
378 'no group by' => TRUE,
379 'search_type' => 'node_search',