Chris@0: getMainPropertyName()); Chris@4: } Chris@4: Chris@4: /** Chris@4: * Provides Views integration for any datetime-based fields. Chris@4: * Chris@4: * Overrides the default Views data for datetime-based fields, adding datetime Chris@4: * views plugins. Modules defining new datetime-based fields may use this Chris@4: * function to simplify Views integration. Chris@4: * Chris@4: * @param \Drupal\field\FieldStorageConfigInterface $field_storage Chris@4: * The field storage config entity. Chris@4: * @param array $data Chris@4: * Field view data or views_field_default_views_data($field_storage) if empty. Chris@4: * @param string $column_name Chris@4: * The schema column name with the datetime value. Chris@4: * Chris@4: * @return array Chris@4: * The array of field views data with the datetime plugin. Chris@4: * Chris@4: * @see datetime_field_views_data() Chris@4: * @see datetime_range_field_views_data() Chris@4: */ Chris@4: function datetime_type_field_views_data_helper(FieldStorageConfigInterface $field_storage, array $data, $column_name) { Chris@0: // @todo This code only covers configurable fields, handle base table fields Chris@0: // in https://www.drupal.org/node/2489476. Chris@4: $data = empty($data) ? views_field_default_views_data($field_storage) : $data; Chris@0: foreach ($data as $table_name => $table_data) { Chris@0: // Set the 'datetime' filter type. Chris@4: $data[$table_name][$field_storage->getName() . '_' . $column_name]['filter']['id'] = 'datetime'; Chris@0: Chris@0: // Set the 'datetime' argument type. Chris@4: $data[$table_name][$field_storage->getName() . '_' . $column_name]['argument']['id'] = 'datetime'; Chris@0: Chris@0: // Create year, month, and day arguments. Chris@4: $group = $data[$table_name][$field_storage->getName() . '_' . $column_name]['group']; Chris@0: $arguments = [ Chris@0: // Argument type => help text. Chris@0: 'year' => t('Date in the form of YYYY.'), Chris@0: 'month' => t('Date in the form of MM (01 - 12).'), Chris@0: 'day' => t('Date in the form of DD (01 - 31).'), Chris@0: 'week' => t('Date in the form of WW (01 - 53).'), Chris@0: 'year_month' => t('Date in the form of YYYYMM.'), Chris@0: 'full_date' => t('Date in the form of CCYYMMDD.'), Chris@0: ]; Chris@0: foreach ($arguments as $argument_type => $help_text) { Chris@4: $column_name_text = $column_name === $field_storage->getMainPropertyName() ? '' : ':' . $column_name; Chris@4: $data[$table_name][$field_storage->getName() . '_' . $column_name . '_' . $argument_type] = [ Chris@4: 'title' => t('@label@column (@argument)', [ Chris@4: '@label' => $field_storage->getLabel(), Chris@4: '@column' => $column_name_text, Chris@4: '@argument' => $argument_type, Chris@4: ]), Chris@0: 'help' => $help_text, Chris@0: 'argument' => [ Chris@4: 'field' => $field_storage->getName() . '_' . $column_name, Chris@0: 'id' => 'datetime_' . $argument_type, Chris@0: 'entity_type' => $field_storage->getTargetEntityTypeId(), Chris@0: 'field_name' => $field_storage->getName(), Chris@0: ], Chris@0: 'group' => $group, Chris@0: ]; Chris@0: } Chris@0: Chris@0: // Set the 'datetime' sort handler. Chris@4: $data[$table_name][$field_storage->getName() . '_' . $column_name]['sort']['id'] = 'datetime'; Chris@0: } Chris@0: Chris@0: return $data; Chris@0: }