5 * Provides views data for the datetime module.
8 use Drupal\field\FieldStorageConfigInterface;
11 * Implements hook_field_views_data().
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';
21 // Set the 'datetime' argument type.
22 $data[$table_name][$field_storage->getName() . '_value']['argument']['id'] = 'datetime';
24 // Create year, month, and day arguments.
25 $group = $data[$table_name][$field_storage->getName() . '_value']['group'];
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.'),
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 . ')',
40 'field' => $field_storage->getName() . '_value',
41 'id' => 'datetime_' . $argument_type,
47 // Set the 'datetime' sort handler.
48 $data[$table_name][$field_storage->getName() . '_value']['sort']['id'] = 'datetime';