comparison core/modules/datetime/datetime.views.inc @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
9 9
10 /** 10 /**
11 * Implements hook_field_views_data(). 11 * Implements hook_field_views_data().
12 */ 12 */
13 function datetime_field_views_data(FieldStorageConfigInterface $field_storage) { 13 function datetime_field_views_data(FieldStorageConfigInterface $field_storage) {
14 return datetime_type_field_views_data_helper($field_storage, [], $field_storage->getMainPropertyName());
15 }
16
17 /**
18 * Provides Views integration for any datetime-based fields.
19 *
20 * Overrides the default Views data for datetime-based fields, adding datetime
21 * views plugins. Modules defining new datetime-based fields may use this
22 * function to simplify Views integration.
23 *
24 * @param \Drupal\field\FieldStorageConfigInterface $field_storage
25 * The field storage config entity.
26 * @param array $data
27 * Field view data or views_field_default_views_data($field_storage) if empty.
28 * @param string $column_name
29 * The schema column name with the datetime value.
30 *
31 * @return array
32 * The array of field views data with the datetime plugin.
33 *
34 * @see datetime_field_views_data()
35 * @see datetime_range_field_views_data()
36 */
37 function datetime_type_field_views_data_helper(FieldStorageConfigInterface $field_storage, array $data, $column_name) {
14 // @todo This code only covers configurable fields, handle base table fields 38 // @todo This code only covers configurable fields, handle base table fields
15 // in https://www.drupal.org/node/2489476. 39 // in https://www.drupal.org/node/2489476.
16 $data = views_field_default_views_data($field_storage); 40 $data = empty($data) ? views_field_default_views_data($field_storage) : $data;
17 foreach ($data as $table_name => $table_data) { 41 foreach ($data as $table_name => $table_data) {
18 // Set the 'datetime' filter type. 42 // Set the 'datetime' filter type.
19 $data[$table_name][$field_storage->getName() . '_value']['filter']['id'] = 'datetime'; 43 $data[$table_name][$field_storage->getName() . '_' . $column_name]['filter']['id'] = 'datetime';
20 44
21 // Set the 'datetime' argument type. 45 // Set the 'datetime' argument type.
22 $data[$table_name][$field_storage->getName() . '_value']['argument']['id'] = 'datetime'; 46 $data[$table_name][$field_storage->getName() . '_' . $column_name]['argument']['id'] = 'datetime';
23 47
24 // Create year, month, and day arguments. 48 // Create year, month, and day arguments.
25 $group = $data[$table_name][$field_storage->getName() . '_value']['group']; 49 $group = $data[$table_name][$field_storage->getName() . '_' . $column_name]['group'];
26 $arguments = [ 50 $arguments = [
27 // Argument type => help text. 51 // Argument type => help text.
28 'year' => t('Date in the form of YYYY.'), 52 'year' => t('Date in the form of YYYY.'),
29 'month' => t('Date in the form of MM (01 - 12).'), 53 'month' => t('Date in the form of MM (01 - 12).'),
30 'day' => t('Date in the form of DD (01 - 31).'), 54 'day' => t('Date in the form of DD (01 - 31).'),
31 'week' => t('Date in the form of WW (01 - 53).'), 55 'week' => t('Date in the form of WW (01 - 53).'),
32 'year_month' => t('Date in the form of YYYYMM.'), 56 'year_month' => t('Date in the form of YYYYMM.'),
33 'full_date' => t('Date in the form of CCYYMMDD.'), 57 'full_date' => t('Date in the form of CCYYMMDD.'),
34 ]; 58 ];
35 foreach ($arguments as $argument_type => $help_text) { 59 foreach ($arguments as $argument_type => $help_text) {
36 $data[$table_name][$field_storage->getName() . '_value_' . $argument_type] = [ 60 $column_name_text = $column_name === $field_storage->getMainPropertyName() ? '' : ':' . $column_name;
37 'title' => $field_storage->getLabel() . ' (' . $argument_type . ')', 61 $data[$table_name][$field_storage->getName() . '_' . $column_name . '_' . $argument_type] = [
62 'title' => t('@label@column (@argument)', [
63 '@label' => $field_storage->getLabel(),
64 '@column' => $column_name_text,
65 '@argument' => $argument_type,
66 ]),
38 'help' => $help_text, 67 'help' => $help_text,
39 'argument' => [ 68 'argument' => [
40 'field' => $field_storage->getName() . '_value', 69 'field' => $field_storage->getName() . '_' . $column_name,
41 'id' => 'datetime_' . $argument_type, 70 'id' => 'datetime_' . $argument_type,
42 'entity_type' => $field_storage->getTargetEntityTypeId(), 71 'entity_type' => $field_storage->getTargetEntityTypeId(),
43 'field_name' => $field_storage->getName(), 72 'field_name' => $field_storage->getName(),
44 ], 73 ],
45 'group' => $group, 74 'group' => $group,
46 ]; 75 ];
47 } 76 }
48 77
49 // Set the 'datetime' sort handler. 78 // Set the 'datetime' sort handler.
50 $data[$table_name][$field_storage->getName() . '_value']['sort']['id'] = 'datetime'; 79 $data[$table_name][$field_storage->getName() . '_' . $column_name]['sort']['id'] = 'datetime';
51 } 80 }
52 81
53 return $data; 82 return $data;
54 } 83 }