Chris@0: getMainPropertyName()); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Provides Views integration for any datetime-based fields. Chris@17: * Chris@17: * Overrides the default Views data for datetime-based fields, adding datetime Chris@17: * views plugins. Modules defining new datetime-based fields may use this Chris@17: * function to simplify Views integration. Chris@17: * Chris@17: * @param \Drupal\field\FieldStorageConfigInterface $field_storage Chris@17: * The field storage config entity. Chris@17: * @param array $data Chris@17: * Field view data or views_field_default_views_data($field_storage) if empty. Chris@17: * @param string $column_name Chris@17: * The schema column name with the datetime value. Chris@17: * Chris@17: * @return array Chris@17: * The array of field views data with the datetime plugin. Chris@17: * Chris@17: * @see datetime_field_views_data() Chris@17: * @see datetime_range_field_views_data() Chris@17: */ Chris@17: 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@17: $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@17: $data[$table_name][$field_storage->getName() . '_' . $column_name]['filter']['id'] = 'datetime'; Chris@0: Chris@0: // Set the 'datetime' argument type. Chris@17: $data[$table_name][$field_storage->getName() . '_' . $column_name]['argument']['id'] = 'datetime'; Chris@0: Chris@0: // Create year, month, and day arguments. Chris@17: $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@17: $column_name_text = $column_name === $field_storage->getMainPropertyName() ? '' : ':' . $column_name; Chris@17: $data[$table_name][$field_storage->getName() . '_' . $column_name . '_' . $argument_type] = [ Chris@17: 'title' => t('@label@column (@argument)', [ Chris@17: '@label' => $field_storage->getLabel(), Chris@17: '@column' => $column_name_text, Chris@17: '@argument' => $argument_type, Chris@17: ]), Chris@0: 'help' => $help_text, Chris@0: 'argument' => [ Chris@17: 'field' => $field_storage->getName() . '_' . $column_name, Chris@0: 'id' => 'datetime_' . $argument_type, Chris@14: 'entity_type' => $field_storage->getTargetEntityTypeId(), Chris@14: '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@17: $data[$table_name][$field_storage->getName() . '_' . $column_name]['sort']['id'] = 'datetime'; Chris@0: } Chris@0: Chris@0: return $data; Chris@0: }