function datetime_type_field_views_data_helper
Same name in other branches
- 9 core/modules/datetime/datetime.views.inc \datetime_type_field_views_data_helper()
- 8.9.x core/modules/datetime/datetime.views.inc \datetime_type_field_views_data_helper()
- 11.x core/modules/datetime/datetime.views.inc \datetime_type_field_views_data_helper()
Provides Views integration for any datetime-based fields.
Overrides the default Views data for datetime-based fields, adding datetime views plugins. Modules defining new datetime-based fields may use this function to simplify Views integration.
Parameters
\Drupal\field\FieldStorageConfigInterface $field_storage: The field storage config entity.
array $data: Field view data or views_field_default_views_data($field_storage) if empty.
string $column_name: The schema column name with the datetime value.
Return value
array The array of field views data with the datetime plugin.
See also
datetime_range_field_views_data()
2 calls to datetime_type_field_views_data_helper()
- datetime_field_views_data in core/
modules/ datetime/ datetime.views.inc - Implements hook_field_views_data().
- datetime_range_field_views_data in core/
modules/ datetime_range/ datetime_range.views.inc - Implements hook_field_views_data().
File
-
core/
modules/ datetime/ datetime.views.inc, line 37
Code
function datetime_type_field_views_data_helper(FieldStorageConfigInterface $field_storage, array $data, $column_name) {
// @todo This code only covers configurable fields, handle base table fields
// in https://www.drupal.org/node/2489476.
$data = empty($data) ? views_field_default_views_data($field_storage) : $data;
foreach ($data as $table_name => $table_data) {
// Set the 'datetime' filter type.
$data[$table_name][$field_storage->getName() . '_' . $column_name]['filter']['id'] = 'datetime';
// Set the 'datetime' argument type.
$data[$table_name][$field_storage->getName() . '_' . $column_name]['argument']['id'] = 'datetime';
// Create year, month, and day arguments.
$group = $data[$table_name][$field_storage->getName() . '_' . $column_name]['group'];
$arguments = [
// Argument type => help text.
'year' => t('Date in the form of YYYY.'),
'month' => t('Date in the form of MM (01 - 12).'),
'day' => t('Date in the form of DD (01 - 31).'),
'week' => t('Date in the form of WW (01 - 53).'),
'year_month' => t('Date in the form of YYYYMM.'),
'full_date' => t('Date in the form of CCYYMMDD.'),
];
foreach ($arguments as $argument_type => $help_text) {
$column_name_text = $column_name === $field_storage->getMainPropertyName() ? '' : ':' . $column_name;
$data[$table_name][$field_storage->getName() . '_' . $column_name . '_' . $argument_type] = [
'title' => t('@label@column (@argument)', [
'@label' => $field_storage->getLabel(),
'@column' => $column_name_text,
'@argument' => $argument_type,
]),
'help' => $help_text,
'argument' => [
'field' => $field_storage->getName() . '_' . $column_name,
'id' => 'datetime_' . $argument_type,
'entity_type' => $field_storage->getTargetEntityTypeId(),
'field_name' => $field_storage->getName(),
],
'group' => $group,
];
}
// Set the 'datetime' sort handler.
$data[$table_name][$field_storage->getName() . '_' . $column_name]['sort']['id'] = 'datetime';
}
return $data;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.