diff --git a/core/modules/datetime/datetime.views.inc b/core/modules/datetime/datetime.views.inc index c12a3aca42a8fdb30ebf30fb808827230a6f3626..d3b0d18617d04b7343a9c668517e8ae41263bd6f 100644 --- a/core/modules/datetime/datetime.views.inc +++ b/core/modules/datetime/datetime.views.inc @@ -26,8 +26,11 @@ function datetime_field_views_data(FieldStorageConfigInterface $field_storage) { $arguments = [ // Argument type => help text. 'year' => t('Date in the form of YYYY.'), - 'month' => t('Date in the form of MM.'), - 'day' => t('Date in the form of DD.'), + '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) { $data[$table_name][$field_storage->getName() . '_value_' . $argument_type] = [ diff --git a/core/modules/datetime/src/Plugin/views/argument/FullDate.php b/core/modules/datetime/src/Plugin/views/argument/FullDate.php new file mode 100644 index 0000000000000000000000000000000000000000..16644a9f7da194757ad9db47ce4b8b4639799f21 --- /dev/null +++ b/core/modules/datetime/src/Plugin/views/argument/FullDate.php @@ -0,0 +1,22 @@ +<?php + +/** + * @file + * Contains \Drupal\datetime\Plugin\views\argument\FullDate. + */ + +namespace Drupal\datetime\Plugin\views\argument; + +/** + * Argument handler for a full date (CCYYMMDD). + * + * @ViewsArgument("datetime_full_date") + */ +class FullDate extends Date { + + /** + * {@inheritdoc} + */ + protected $argFormat = 'Ymd'; + +} diff --git a/core/modules/datetime/src/Plugin/views/argument/WeekDate.php b/core/modules/datetime/src/Plugin/views/argument/WeekDate.php new file mode 100644 index 0000000000000000000000000000000000000000..6b0d8175aceb72e3eca5795c2c3d9245f174f033 --- /dev/null +++ b/core/modules/datetime/src/Plugin/views/argument/WeekDate.php @@ -0,0 +1,22 @@ +<?php + +/** + * @file + * Contains \Drupal\datetime\Plugin\views\argument\WeekDate. + */ + +namespace Drupal\datetime\Plugin\views\argument; + +/** + * Argument handler for a week. + * + * @ViewsArgument("datetime_week") + */ +class WeekDate extends Date { + + /** + * {@inheritdoc} + */ + protected $argFormat = 'W'; + +} diff --git a/core/modules/datetime/src/Plugin/views/argument/YearMonthDate.php b/core/modules/datetime/src/Plugin/views/argument/YearMonthDate.php new file mode 100644 index 0000000000000000000000000000000000000000..1a533bf9fc53dbf9ae745e63c453ca9da315be02 --- /dev/null +++ b/core/modules/datetime/src/Plugin/views/argument/YearMonthDate.php @@ -0,0 +1,22 @@ +<?php + +/** + * @file + * Contains \Drupal\datetime\Plugin\views\argument\YearMonthDate. + */ + +namespace Drupal\datetime\Plugin\views\argument; + +/** + * Argument handler for a year plus month (CCYYMM). + * + * @ViewsArgument("datetime_year_month") + */ +class YearMonthDate extends Date { + + /** + * {@inheritdoc} + */ + protected $argFormat = 'Ym'; + +} diff --git a/core/modules/datetime/src/Tests/Views/ArgumentDateTimeTest.php b/core/modules/datetime/src/Tests/Views/ArgumentDateTimeTest.php index e40868effd1eddab41ad4fb3ab8591672464ed56..ba90110791e5df248df5a77d49662c6d9bd3294f 100644 --- a/core/modules/datetime/src/Tests/Views/ArgumentDateTimeTest.php +++ b/core/modules/datetime/src/Tests/Views/ArgumentDateTimeTest.php @@ -138,4 +138,71 @@ public function testDatetimeArgumentAll() { $view->destroy(); } + /** + * Test week WW argument. + */ + public function testDatetimeArgumentWeek() { + $view = Views::getView('test_argument_datetime'); + // The 'embed_4' display has WW argument. + $view->setDisplay('embed_4'); + + $this->executeView($view, ['41']); + $expected = []; + $expected[] = ['nid' => $this->nodes[0]->id()]; + $expected[] = ['nid' => $this->nodes[1]->id()]; + $this->assertIdenticalResultset($view, $expected, $this->map); + $view->destroy(); + + $view->setDisplay('embed_4'); + $this->executeView($view, ['01']); + $expected = []; + $expected[] = ['nid' => $this->nodes[2]->id()]; + $this->assertIdenticalResultset($view, $expected, $this->map); + $view->destroy(); + } + + /** + * Test full_date CCYYMMDD argument. + */ + public function testDatetimeArgumentFullDate() { + $view = Views::getView('test_argument_datetime'); + // The 'embed_5' display has CCYYMMDD argument. + $view->setDisplay('embed_5'); + + $this->executeView($view, ['20001010']); + $expected = []; + $expected[] = ['nid' => $this->nodes[0]->id()]; + $this->assertIdenticalResultset($view, $expected, $this->map); + $view->destroy(); + + $view->setDisplay('embed_5'); + $this->executeView($view, ['20020101']); + $expected = []; + $expected[] = ['nid' => $this->nodes[2]->id()]; + $this->assertIdenticalResultset($view, $expected, $this->map); + $view->destroy(); + } + + /** + * Test year_month CCYYMM argument. + */ + public function testDatetimeArgumentYearMonth() { + $view = Views::getView('test_argument_datetime'); + // The 'embed_6' display has CCYYMM argument. + $view->setDisplay('embed_6'); + + $this->executeView($view, ['200010']); + $expected = []; + $expected[] = ['nid' => $this->nodes[0]->id()]; + $this->assertIdenticalResultset($view, $expected, $this->map); + $view->destroy(); + + $view->setDisplay('embed_6'); + $this->executeView($view, ['200201']); + $expected = []; + $expected[] = ['nid' => $this->nodes[2]->id()]; + $this->assertIdenticalResultset($view, $expected, $this->map); + $view->destroy(); + } + } diff --git a/core/modules/datetime/tests/modules/datetime_test/test_views/views.view.test_argument_datetime.yml b/core/modules/datetime/tests/modules/datetime_test/test_views/views.view.test_argument_datetime.yml index 7f3abec2292e186f6846226769de213484d69048..24900e6a0871bbc5332932733267ab8bc8ab40ce 100644 --- a/core/modules/datetime/tests/modules/datetime_test/test_views/views.view.test_argument_datetime.yml +++ b/core/modules/datetime/tests/modules/datetime_test/test_views/views.view.test_argument_datetime.yml @@ -97,3 +97,45 @@ display: id: embed_2 display_title: '' position: null + embed_4: + display_options: + defaults: + arguments: false + arguments: + field_date_value_day: + field: field_date_value_week + id: field_date_value + table: node__field_date + plugin_id: datetime_week + display_plugin: embed + id: embed_4 + display_title: '' + position: null + embed_5: + display_options: + defaults: + arguments: false + arguments: + field_date_value_day: + field: field_date_value_full_date + id: field_date_value + table: node__field_date + plugin_id: datetime_full_date + display_plugin: embed + id: embed_5 + display_title: '' + position: null + embed_6: + display_options: + defaults: + arguments: false + arguments: + field_date_value_day: + field: field_date_value_year_month + id: field_date_value + table: node__field_date + plugin_id: datetime_year_month + display_plugin: embed + id: embed_6 + display_title: '' + position: null