Problem/Motivation
Entity views data classes such as NodeViewsData are doing things like this to add pseudo-arguments to Views for pieces of dates:
$data['node_field_data']['created_fulldate'] = array(
'title' => t('Created date'),
'help' => t('Date in the form of CCYYMMDD.'),
'argument' => array(
'field' => 'created',
'id' => 'date_fulldate',
),
);
$data['node_field_data']['created_year_month'] = array(
'title' => t('Created year + month'),
'help' => t('Date in the form of YYYYMM.'),
'argument' => array(
'field' => 'created',
'id' => 'date_year_month',
),
);
$data['node_field_data']['created_year'] = array(
'title' => t('Created year'),
'help' => t('Date in the form of YYYY.'),
'argument' => array(
'field' => 'created',
'id' => 'date_year',
),
);
$data['node_field_data']['created_month'] = array(
'title' => t('Created month'),
'help' => t('Date in the form of MM (01 - 12).'),
'argument' => array(
'field' => 'created',
'id' => 'date_month',
),
);
$data['node_field_data']['created_day'] = array(
'title' => t('Created day'),
'help' => t('Date in the form of DD (01 - 31).'),
'argument' => array(
'field' => 'created',
'id' => 'date_day',
),
);
$data['node_field_data']['created_week'] = array(
'title' => t('Created week'),
'help' => t('Date in the form of WW (01 - 53).'),
'argument' => array(
'field' => 'created',
'id' => 'date_week',
),
);
It would be better if there was a base Views solution to this.
Proposed resolution
Add these arguments in a centralized way for all date fields.
Comments
Comment #1
jhodgdonAdding issue summary.
Comment #2
jhodgdonComment #3
jhodgdonJust realized this is only about arguments, not field formatting.
Comment #4
clemens.tolboomThis should be a bug as those 'pseudo' arguments are not applied to a custom date field as reported in #2567815: Add week, date, and year-month Views argument plugins.
We have now two code path for date based argument handlers
Through
and
core/modules/datetime/src/Plugin/views/argument/Day|Month|Year which is missing at least week and year+month
Comment #5
mpdonadio#4 They are different paths because they are different types in Drupal. The node updated, node created, and other entity properties are 'timestamp', and IIRC can't be created via the UI forms on entities. The others are provided by datatime.module, and are a configurable DataTime type.
Comment #6
clemens.tolboom@mpdonadio so it's OK to have to tell users "we have two types of date fields so take care when using them as views arguments ... and they have different options like missing week filter or year-month"?
We now have to document this twice and confuse lot's of users.
That's why I changed this issue type to a bug.
Comment #7
mpdonadio#6, yeah, this is confusing and results in bad UX, but I don't think this is really a bug since nothing really breaks (eg, you can't apply timestamp filter to a datetime field), a Views maintainer created this as a Task.
If I can read @dawehner's mind on this one, he want to move this above code to somewhere in the base Views classes and allow the entity classes to be able to say "I have a timestamp, expose it" without having to manually add it each time, and keep the UX the same (for now).
Comment #8
jhodgdonLet's not argue about whether it's a task "Add support for something and make the UI consistent" or a usability bug. That will not help us get it fixed.
Comment #14
johnsiciliAny movement on this? Looking to make this happen so I can group events by their event date with a more human readable date.
Comment #18
it-cruComment #19
pasquallehttps://git.drupalcode.org/project/drupal/-/blob/9.3.x/core/modules/node...