diff --git a/core/modules/datetime/datetime.views.inc b/core/modules/datetime/datetime.views.inc index d3b0d18..e3f3789 100644 --- a/core/modules/datetime/datetime.views.inc +++ b/core/modules/datetime/datetime.views.inc @@ -13,40 +13,42 @@ function datetime_field_views_data(FieldStorageConfigInterface $field_storage) { // @todo This code only covers configurable fields, handle base table fields // in https://www.drupal.org/node/2489476. - $data = views_field_default_views_data($field_storage); - foreach ($data as $table_name => $table_data) { - // Set the 'datetime' filter type. - $data[$table_name][$field_storage->getName() . '_value']['filter']['id'] = 'datetime'; + if ($field_storage->getType() == 'datetime') { + $data = views_field_default_views_data($field_storage); + foreach ($data as $table_name => $table_data) { + // Set the 'datetime' filter type. + $data[$table_name][$field_storage->getName() . '_value']['filter']['id'] = 'datetime'; - // Set the 'datetime' argument type. - $data[$table_name][$field_storage->getName() . '_value']['argument']['id'] = 'datetime'; + // Set the 'datetime' argument type. + $data[$table_name][$field_storage->getName() . '_value']['argument']['id'] = 'datetime'; - // Create year, month, and day arguments. - $group = $data[$table_name][$field_storage->getName() . '_value']['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) { - $data[$table_name][$field_storage->getName() . '_value_' . $argument_type] = [ - 'title' => $field_storage->getLabel() . ' (' . $argument_type . ')', - 'help' => $help_text, - 'argument' => [ - 'field' => $field_storage->getName() . '_value', - 'id' => 'datetime_' . $argument_type, - ], - 'group' => $group, + // Create year, month, and day arguments. + $group = $data[$table_name][$field_storage->getName() . '_value']['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) { + $data[$table_name][$field_storage->getName() . '_value_' . $argument_type] = [ + 'title' => $field_storage->getLabel() . ' (' . $argument_type . ')', + 'help' => $help_text, + 'argument' => [ + 'field' => $field_storage->getName() . '_value', + 'id' => 'datetime_' . $argument_type, + ], + 'group' => $group, + ]; + } + + // Set the 'datetime' sort handler. + $data[$table_name][$field_storage->getName() . '_value']['sort']['id'] = 'datetime'; } - // Set the 'datetime' sort handler. - $data[$table_name][$field_storage->getName() . '_value']['sort']['id'] = 'datetime'; + return $data; } - - return $data; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeItem.php b/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeItem.php index 49d6f49..7e01116 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeItem.php +++ b/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeItem.php @@ -14,7 +14,7 @@ * * @FieldType( * id = "daterange", - * label = @Translation("Date Range"), + * label = @Translation("Date range"), * description = @Translation("Create and store date ranges."), * default_widget = "daterange_default", * default_formatter = "daterange_default", diff --git a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php index 9c62f82..7d4013d 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php +++ b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php @@ -169,7 +169,7 @@ public function validateStartEnd($element, FormStateInterface $form_state) { if ($start_date->format('U') !== $end_date->format('U')) { $interval = $start_date->diff($end_date); if ($interval->invert === 1) { - $form_state->setError($element, $this->t('Start date should be equal to, or before, end date')); + $form_state->setError($element, $this->t('The @title end date cannot be before the start date', ['@title' => $element['#title']])); } } } diff --git a/core/modules/datetime/src/Tests/DateRangeFieldTest.php b/core/modules/datetime/src/Tests/DateRangeFieldTest.php index e1d5ca7..3ba2533 100644 --- a/core/modules/datetime/src/Tests/DateRangeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateRangeFieldTest.php @@ -1089,7 +1089,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => '12:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Start date should be equal to, or before, end date', 'End date before start date has been caught.'); + $this->assertText(t('The @title end date cannot be before the start date', ['@title' => $field_name]), 'End date before start date has been caught.'); $edit = [ "{$field_name}[0][value][date]" => '2012-12-01', @@ -1098,7 +1098,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => '11:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('Start date should be equal to, or before, end date', 'End time before start time has been caught.'); + $this->assertText(t('The @title end date cannot be before the start date', ['@title' => $field_name]), 'End time before start time has been caught.'); } /**