FileViewsData::getViewsData

public FileViewsData::getViewsData()

Returns views data for the entity type.

Return value

array Views data in the format of hook_views_data().

Overrides EntityViewsData::getViewsData

File

core/modules/file/src/FileViewsData.php, line 15

Class

FileViewsData
Provides views data for the file entity type.

Namespace

Drupal\file

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
public function getViewsData() {
  $data = parent::getViewsData();
 
  // @TODO There is no corresponding information in entity metadata.
  $data['file_managed']['table']['base']['help'] = $this->t('Files maintained by Drupal and various modules.');
  $data['file_managed']['table']['base']['defaults']['field'] = 'filename';
  $data['file_managed']['table']['wizard_id'] = 'file_managed';
 
  $data['file_managed']['fid']['argument'] = array(
    'id' => 'file_fid',
    // The field to display in the summary.
    'name field' => 'filename',
    'numeric' => TRUE,
  );
  $data['file_managed']['fid']['relationship'] = array(
    'title' => $this->t('File usage'),
    'help' => $this->t('Relate file entities to their usage.'),
    'id' => 'standard',
    'base' => 'file_usage',
    'base field' => 'fid',
    'field' => 'fid',
    'label' => $this->t('File usage'),
  );
 
  $data['file_managed']['uri']['field']['default_formatter'] = 'file_uri';
 
  $data['file_managed']['filemime']['field']['default_formatter'] = 'file_filemime';
 
  $data['file_managed']['extension'] = array(
    'title' => $this->t('Extension'),
    'help' => $this->t('The extension of the file.'),
    'real field' => 'filename',
    'field' => array(
      'entity_type' => 'file',
      'field_name' => 'filename',
      'default_formatter' => 'file_extension',
      'id' => 'field',
      'click sortable' => FALSE,
    ),
  );
 
  $data['file_managed']['filesize']['field']['default_formatter'] = 'file_size';
 
  $data['file_managed']['status']['field']['default_formatter_settings'] = [
    'format' => 'custom',
    'format_custom_false' => $this->t('Temporary'),
    'format_custom_true' => $this->t('Permanent'),
  ];
  $data['file_managed']['status']['filter']['id'] = 'file_status';
 
  $data['file_managed']['uid']['relationship']['title'] = $this->t('User who uploaded');
  $data['file_managed']['uid']['relationship']['label'] = $this->t('User who uploaded');
 
  $data['file_usage']['table']['group'] = $this->t('File Usage');
 
  // Provide field-type-things to several base tables; on the core files table
  // ("file_managed") so that we can create relationships from files to
  // entities, and then on each core entity type base table so that we can
  // provide general relationships between entities and files.
  $data['file_usage']['table']['join'] = array(
    'file_managed' => array(
      'field' => 'fid',
      'left_field' => 'fid',
    ),
    // Link ourselves to the {node_field_data} table
    // so we can provide node->file relationships.
    'node_field_data' => array(
      'field' => 'id',
      'left_field' => 'nid',
      'extra' => array(array('field' => 'type', 'value' => 'node')),
    ),
    // Link ourselves to the {users_field_data} table
    // so we can provide user->file relationships.
    'users_field_data' => array(
      'field' => 'id',
      'left_field' => 'uid',
      'extra' => array(array('field' => 'type', 'value' => 'user')),
    ),
    // Link ourselves to the {comment_field_data} table
    // so we can provide comment->file relationships.
    'comment' => array(
      'field' => 'id',
      'left_field' => 'cid',
      'extra' => array(array('field' => 'type', 'value' => 'comment')),
    ),
    // Link ourselves to the {taxonomy_term_field_data} table
    // so we can provide taxonomy_term->file relationships.
    'taxonomy_term_data' => array(
      'field' => 'id',
      'left_field' => 'tid',
      'extra' => array(array('field' => 'type', 'value' => 'taxonomy_term')),
    ),
  );
 
  // Provide a relationship between the files table and each entity type,
  // and between each entity type and the files table. Entity->file
  // relationships are type-restricted in the joins declared above, and
  // file->entity relationships are type-restricted in the relationship
  // declarations below.
 
  // Describes relationships between files and nodes.
  $data['file_usage']['file_to_node'] = array(
    'title' => $this->t('Content'),
    'help' => $this->t('Content that is associated with this file, usually because this file is in a field on the content.'),
    // Only provide this field/relationship/etc.,
    // when the 'file_managed' base table is present.
    'skip base' => array('node_field_data', 'node_field_revision', 'users_field_data', 'comment_field_data', 'taxonomy_term_field_data'),
    'real field' => 'id',
    'relationship' => array(
      'title' => $this->t('Content'),
      'label' => $this->t('Content'),
      'base' => 'node_field_data',
      'base field' => 'nid',
      'relationship field' => 'id',
      'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'node')),
    ),
  );
  $data['file_usage']['node_to_file'] = array(
    'title' => $this->t('File'),
    'help' => $this->t('A file that is associated with this node, usually because it is in a field on the node.'),
    // Only provide this field/relationship/etc.,
    // when the 'node' base table is present.
    'skip base' => array('file_managed', 'users_field_data', 'comment_field_data', 'taxonomy_term_field_data'),
    'real field' => 'fid',
    'relationship' => array(
      'title' => $this->t('File'),
      'label' => $this->t('File'),
      'base' => 'file_managed',
      'base field' => 'fid',
      'relationship field' => 'fid',
    ),
  );
 
  // Describes relationships between files and users.
  $data['file_usage']['file_to_user'] = array(
    'title' => $this->t('User'),
    'help' => $this->t('A user that is associated with this file, usually because this file is in a field on the user.'),
    // Only provide this field/relationship/etc.,
    // when the 'file_managed' base table is present.
    'skip base' => array('node_field_data', 'node_field_revision', 'users_field_data', 'comment_field_data', 'taxonomy_term_field_data'),
    'real field' => 'id',
    'relationship' => array(
      'title' => $this->t('User'),
      'label' => $this->t('User'),
      'base' => 'users',
      'base field' => 'uid',
      'relationship field' => 'id',
      'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'user')),
    ),
  );
  $data['file_usage']['user_to_file'] = array(
    'title' => $this->t('File'),
    'help' => $this->t('A file that is associated with this user, usually because it is in a field on the user.'),
    // Only provide this field/relationship/etc.,
    // when the 'users' base table is present.
    'skip base' => array('file_managed', 'node_field_data', 'node_field_revision', 'comment_field_data', 'taxonomy_term_field_data'),
    'real field' => 'fid',
    'relationship' => array(
      'title' => $this->t('File'),
      'label' => $this->t('File'),
      'base' => 'file_managed',
      'base field' => 'fid',
      'relationship field' => 'fid',
    ),
  );
 
  // Describes relationships between files and comments.
  $data['file_usage']['file_to_comment'] = array(
    'title' => $this->t('Comment'),
    'help' => $this->t('A comment that is associated with this file, usually because this file is in a field on the comment.'),
    // Only provide this field/relationship/etc.,
    // when the 'file_managed' base table is present.
    'skip base' => array('node_field_data', 'node_field_revision', 'users_field_data', 'comment_field_data', 'taxonomy_term_field_data'),
    'real field' => 'id',
    'relationship' => array(
      'title' => $this->t('Comment'),
      'label' => $this->t('Comment'),
      'base' => 'comment_field_data',
      'base field' => 'cid',
      'relationship field' => 'id',
      'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'comment')),
    ),
  );
  $data['file_usage']['comment_to_file'] = array(
    'title' => $this->t('File'),
    'help' => $this->t('A file that is associated with this comment, usually because it is in a field on the comment.'),
    // Only provide this field/relationship/etc.,
    // when the 'comment' base table is present.
    'skip base' => array('file_managed', 'node_field_data', 'node_field_revision', 'users_field_data', 'taxonomy_term_field_data'),
    'real field' => 'fid',
    'relationship' => array(
      'title' => $this->t('File'),
      'label' => $this->t('File'),
      'base' => 'file_managed',
      'base field' => 'fid',
      'relationship field' => 'fid',
    ),
  );
 
  // Describes relationships between files and taxonomy_terms.
  $data['file_usage']['file_to_taxonomy_term'] = array(
    'title' => $this->t('Taxonomy Term'),
    'help' => $this->t('A taxonomy term that is associated with this file, usually because this file is in a field on the taxonomy term.'),
    // Only provide this field/relationship/etc.,
    // when the 'file_managed' base table is present.
    'skip base' => array('node_field_data', 'node_field_revision', 'users_field_data', 'comment_field_data', 'taxonomy_term_field_data'),
    'real field' => 'id',
    'relationship' => array(
      'title' => $this->t('Taxonomy Term'),
      'label' => $this->t('Taxonomy Term'),
      'base' => 'taxonomy_term_data',
      'base field' => 'tid',
      'relationship field' => 'id',
      'extra' => array(array('table' => 'file_usage', 'field' => 'type', 'operator' => '=', 'value' => 'taxonomy_term')),
    ),
  );
  $data['file_usage']['taxonomy_term_to_file'] = array(
    'title' => $this->t('File'),
    'help' => $this->t('A file that is associated with this taxonomy term, usually because it is in a field on the taxonomy term.'),
    // Only provide this field/relationship/etc.,
    // when the 'taxonomy_term_data' base table is present.
    'skip base' => array('file_managed', 'node_field_data', 'node_field_revision', 'users_field_data', 'comment_field_data'),
    'real field' => 'fid',
    'relationship' => array(
      'title' => $this->t('File'),
      'label' => $this->t('File'),
      'base' => 'file_managed',
      'base field' => 'fid',
      'relationship field' => 'fid',
    ),
  );
 
  // Provide basic fields from the {file_usage} table to all of the base tables
  // we've declared joins to, because there is no 'skip base' property on these
  // fields.
  $data['file_usage']['module'] = array(
    'title' => $this->t('Module'),
    'help' => $this->t('The module managing this file relationship.'),
    'field' => array(
      'id' => 'standard',
    ),
    'filter' => array(
      'id' => 'string',
    ),
    'argument' => array(
      'id' => 'string',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );
  $data['file_usage']['type'] = array(
    'title' => $this->t('Entity type'),
    'help' => $this->t('The type of entity that is related to the file.'),
    'field' => array(
      'id' => 'standard',
    ),
    'filter' => array(
      'id' => 'string',
    ),
    'argument' => array(
      'id' => 'string',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );
  $data['file_usage']['id'] = array(
    'title' => $this->t('Entity ID'),
    'help' => $this->t('The ID of the entity that is related to the file.'),
    'field' => array(
      'id' => 'numeric',
    ),
    'argument' => array(
      'id' => 'numeric',
    ),
    'filter' => array(
      'id' => 'numeric',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );
  $data['file_usage']['count'] = array(
    'title' => $this->t('Use count'),
    'help' => $this->t('The number of times the file is used by this entity.'),
    'field' => array(
      'id' => 'numeric',
    ),
    'filter' => array(
      'id' => 'numeric',
    ),
    'sort' => array(
      'id' => 'standard',
    ),
  );
  $data['file_usage']['entity_label'] = array(
    'title' => $this->t('Entity label'),
    'help' => $this->t('The label of the entity that is related to the file.'),
    'real field' => 'id',
    'field' => array(
      'id' => 'entity_label',
      'entity type field' => 'type',
    ),
  );
 
  return $data;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.