datetime.views.inc 1.8 KB

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