tracker.views.inc 4.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<?php

/**
 * @file
 * Provide views data for tracker.module.
 */

/**
 * Implements hook_views_data().
 */
function tracker_views_data() {
12
  $data = [];
13 14

  $data['tracker_node']['table']['group'] = t('Tracker');
15 16
  $data['tracker_node']['table']['join'] = [
    'node_field_data' => [
17 18 19
      'type' => 'INNER',
      'left_field' => 'nid',
      'field' => 'nid',
20 21 22
    ],
  ];
  $data['tracker_node']['nid'] = [
23 24
    'title' => t('Nid'),
    'help' => t('The node ID of the node.'),
25
    'field' => [
26
      'id' => 'node',
27 28
    ],
    'argument' => [
29 30 31 32
      'id' => 'node_nid',
      'name field' => 'title',
      'numeric' => TRUE,
      'validate type' => 'nid',
33 34
    ],
    'filter' => [
35
      'id' => 'numeric',
36 37
    ],
    'sort' => [
38
      'id' => 'standard',
39 40 41
    ],
  ];
  $data['tracker_node']['published'] = [
42 43
    'title' => t('Published'),
    'help' => t('Whether or not the node is published.'),
44
    'field' => [
45
      'id' => 'boolean',
46 47
    ],
    'filter' => [
48 49 50 51 52
      'id' => 'boolean',
      'label' => t('Published'),
      'type' => 'yes-no',
      'accept null' => TRUE,
      'use_equal' => TRUE,
53 54
    ],
    'sort' => [
55
      'id' => 'standard',
56 57 58
    ],
  ];
  $data['tracker_node']['changed'] = [
59 60
    'title' => t('Updated date'),
    'help' => t('The date the node was last updated.'),
61
    'field' => [
62
      'id' => 'date',
63 64
    ],
    'sort' => [
65
      'id' => 'date',
66 67
    ],
    'filter' => [
68
      'id' => 'date',
69 70
    ],
  ];
71 72

  $data['tracker_user']['table']['group'] = t('Tracker - User');
73 74
  $data['tracker_user']['table']['join'] = [
    'node_field_data' => [
75 76 77
      'type' => 'INNER',
      'left_field' => 'nid',
      'field' => 'nid',
78 79
    ],
    'user_field_data' => [
80 81 82
      'type' => 'INNER',
      'left_field' => 'uid',
      'field' => 'uid',
83 84 85
    ],
  ];
  $data['tracker_user']['nid'] = [
86 87
    'title' => t('Nid'),
    'help' => t('The node ID of the node a user created or commented on. You must use an argument or filter on UID or you will get misleading results using this field.'),
88
    'field' => [
89
      'id' => 'node',
90 91
    ],
    'argument' => [
92 93 94 95
      'id' => 'node_nid',
      'name field' => 'title',
      'numeric' => TRUE,
      'validate type' => 'nid',
96 97
    ],
    'filter' => [
98
      'id' => 'numeric',
99 100
    ],
    'sort' => [
101
      'id' => 'standard',
102 103 104
    ],
  ];
  $data['tracker_user']['uid'] = [
105 106
    'title' => t('Uid'),
    'help' => t('The user ID of a user who touched the node (either created or commented on it).'),
107
    'field' => [
108
      'id' => 'user_name',
109 110
    ],
    'argument' => [
111 112
      'id' => 'user_uid',
      'name field' => 'name',
113 114
    ],
    'filter' => [
115 116
      'title' => t('Name'),
      'id' => 'user_name',
117 118
    ],
    'sort' => [
119
      'id' => 'standard',
120 121 122
    ],
  ];
  $data['tracker_user']['published'] = [
123 124
    'title' => t('Published'),
    'help' => t('Whether or not the node is published. You must use an argument or filter on UID or you will get misleading results using this field.'),
125
    'field' => [
126
      'id' => 'boolean',
127 128
    ],
    'filter' => [
129 130 131 132 133
      'id' => 'boolean',
      'label' => t('Published'),
      'type' => 'yes-no',
      'accept null' => TRUE,
      'use_equal' => TRUE,
134 135
    ],
    'sort' => [
136
      'id' => 'standard',
137 138 139
    ],
  ];
  $data['tracker_user']['changed'] = [
140 141
    'title' => t('Updated date'),
    'help' => t('The date the node was last updated or commented on. You must use an argument or filter on UID or you will get misleading results using this field.'),
142
    'field' => [
143
      'id' => 'date',
144 145
    ],
    'sort' => [
146
      'id' => 'date',
147 148
    ],
    'filter' => [
149
      'id' => 'date',
150 151
    ],
  ];
152 153 154 155 156 157 158 159 160

  return $data;
}

/**
 * Implements hook_views_data_alter().
 */
function tracker_views_data_alter(&$data) {
  // Provide additional uid_touch handlers which are handled by tracker
161
  $data['node_field_data']['uid_touch_tracker'] = [
162 163 164
    'group' => t('Tracker - User'),
    'title' => t('User posted or commented'),
    'help' => t('Display nodes only if a user posted the node or commented on the node.'),
165
    'argument' => [
166
      'field' => 'uid',
167
      'name table' => 'users_field_data',
168 169 170
      'name field' => 'name',
      'id' => 'tracker_user_uid',
      'no group by' => TRUE,
171 172
    ],
    'filter' => [
173
      'field' => 'uid',
174
      'name table' => 'users_field_data',
175 176
      'name field' => 'name',
      'id' => 'tracker_user_uid'
177 178
    ],
  ];
179
}