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