Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Provides views data for the datetime module.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\field\FieldStorageConfigInterface;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Implements hook_field_views_data().
|
Chris@0
|
12 */
|
Chris@0
|
13 function datetime_field_views_data(FieldStorageConfigInterface $field_storage) {
|
Chris@0
|
14 // @todo This code only covers configurable fields, handle base table fields
|
Chris@0
|
15 // in https://www.drupal.org/node/2489476.
|
Chris@0
|
16 $data = views_field_default_views_data($field_storage);
|
Chris@0
|
17 foreach ($data as $table_name => $table_data) {
|
Chris@0
|
18 // Set the 'datetime' filter type.
|
Chris@0
|
19 $data[$table_name][$field_storage->getName() . '_value']['filter']['id'] = 'datetime';
|
Chris@0
|
20
|
Chris@0
|
21 // Set the 'datetime' argument type.
|
Chris@0
|
22 $data[$table_name][$field_storage->getName() . '_value']['argument']['id'] = 'datetime';
|
Chris@0
|
23
|
Chris@0
|
24 // Create year, month, and day arguments.
|
Chris@0
|
25 $group = $data[$table_name][$field_storage->getName() . '_value']['group'];
|
Chris@0
|
26 $arguments = [
|
Chris@0
|
27 // Argument type => help text.
|
Chris@0
|
28 'year' => t('Date in the form of YYYY.'),
|
Chris@0
|
29 'month' => t('Date in the form of MM (01 - 12).'),
|
Chris@0
|
30 'day' => t('Date in the form of DD (01 - 31).'),
|
Chris@0
|
31 'week' => t('Date in the form of WW (01 - 53).'),
|
Chris@0
|
32 'year_month' => t('Date in the form of YYYYMM.'),
|
Chris@0
|
33 'full_date' => t('Date in the form of CCYYMMDD.'),
|
Chris@0
|
34 ];
|
Chris@0
|
35 foreach ($arguments as $argument_type => $help_text) {
|
Chris@0
|
36 $data[$table_name][$field_storage->getName() . '_value_' . $argument_type] = [
|
Chris@0
|
37 'title' => $field_storage->getLabel() . ' (' . $argument_type . ')',
|
Chris@0
|
38 'help' => $help_text,
|
Chris@0
|
39 'argument' => [
|
Chris@0
|
40 'field' => $field_storage->getName() . '_value',
|
Chris@0
|
41 'id' => 'datetime_' . $argument_type,
|
Chris@0
|
42 ],
|
Chris@0
|
43 'group' => $group,
|
Chris@0
|
44 ];
|
Chris@0
|
45 }
|
Chris@0
|
46
|
Chris@0
|
47 // Set the 'datetime' sort handler.
|
Chris@0
|
48 $data[$table_name][$field_storage->getName() . '_value']['sort']['id'] = 'datetime';
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 return $data;
|
Chris@0
|
52 }
|