annotate core/modules/datetime/datetime.views.inc @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children 129ea1e6d783
rev   line source
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@14 42 'entity_type' => $field_storage->getTargetEntityTypeId(),
Chris@14 43 'field_name' => $field_storage->getName(),
Chris@0 44 ],
Chris@0 45 'group' => $group,
Chris@0 46 ];
Chris@0 47 }
Chris@0 48
Chris@0 49 // Set the 'datetime' sort handler.
Chris@0 50 $data[$table_name][$field_storage->getName() . '_value']['sort']['id'] = 'datetime';
Chris@0 51 }
Chris@0 52
Chris@0 53 return $data;
Chris@0 54 }