diff --git a/core/modules/datetime/datetime.views.inc b/core/modules/datetime/datetime.views.inc index e3f3789..d82259e 100644 --- a/core/modules/datetime/datetime.views.inc +++ b/core/modules/datetime/datetime.views.inc @@ -11,44 +11,46 @@ * Implements hook_field_views_data(). */ function datetime_field_views_data(FieldStorageConfigInterface $field_storage) { + if ($field_storage->getType() !== 'datetime') { + return []; + } + // @todo This code only covers configurable fields, handle base table fields // in https://www.drupal.org/node/2489476. - 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'; - - // 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.'), + $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'; + + // 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, ]; - 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'; } - return $data; + // Set the 'datetime' sort handler. + $data[$table_name][$field_storage->getName() . '_value']['sort']['id'] = 'datetime'; } + + return $data; } diff --git a/core/modules/datetime/src/DateTimeComputed.php b/core/modules/datetime/src/DateTimeComputed.php index 49f0512..1a19a7a 100644 --- a/core/modules/datetime/src/DateTimeComputed.php +++ b/core/modules/datetime/src/DateTimeComputed.php @@ -40,7 +40,7 @@ public function getValue($langcode = NULL) { return $this->date; } - /** @var \Drupal\Core\Field\FieldItemBase $item */ + /** @var \Drupal\Core\Field\FieldItemInterface $item */ $item = $this->getParent(); $value = $item->{($this->definition->getSetting('date source'))}; $type = $item->getFieldDefinition()->getType(); diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php index 1834d4c..6fa9555 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php @@ -81,7 +81,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { /** * {@inheritdoc} */ - protected function formatDate($date) { + protected function formatDate(DrupalDateTime $date) { $format = $this->getSetting('date_format'); $timezone = $this->getSetting('timezone_override') ?: $date->getTimezone()->getName(); return $this->dateFormatter->format($date->getTimestamp(), 'custom', $format, $timezone != '' ? $timezone : NULL); diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php index 9006fc8..24eb436 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php @@ -117,7 +117,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { /** * {@inheritdoc} */ - protected function formatDate($date) { + protected function formatDate(DrupalDateTime $date) { $format_type = $this->getSetting('format_type'); $timezone = $this->getSetting('timezone_override') ?: $date->getTimezone()->getName(); return $this->dateFormatter->format($date->getTimestamp(), $format_type, '', $timezone != '' ? $timezone : NULL); @@ -139,7 +139,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) { $form['format_type'] = [ '#type' => 'select', - '#title' => t('Date format'), + '#title' => $this->t('Date format'), '#description' => $this->t('Choose a format for displaying the dates. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date.'), '#options' => $options, '#default_value' => $this->getSetting('format_type'), diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeFormatterBase.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeFormatterBase.php index 56f4ac0..bc2f17a 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeFormatterBase.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeFormatterBase.php @@ -85,7 +85,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration['view_mode'], $configuration['third_party_settings'], $container->get('date.formatter'), - $container->get('entity.manager')->getStorage('date_format'), + $container->get('entity_type.manager')->getStorage('date_format'), $container->get('request_stack') ); } @@ -150,7 +150,7 @@ public function settingsSummary() { * @return string * A formatted date range string using the chosen format. */ - abstract protected function formatDate($date); + abstract protected function formatDate(DrupalDateTime $date); /** * Sets the proper time zone on a DrupalDateTime object for the current user. diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php index 5bdcc6a..91c0560 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php @@ -2,6 +2,7 @@ namespace Drupal\datetime\Plugin\Field\FieldFormatter; +use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Field\FieldItemListInterface; use Drupal\datetime\Plugin\Field\FieldType\DateRangeItem; @@ -70,7 +71,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { /** * {@inheritdoc} */ - protected function formatDate($date) { + protected function formatDate(DrupalDateTime $date) { $format = $this->getFieldSetting('daterange_type') == DateRangeItem::DATERANGE_TYPE_DATE ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT; $timezone = $this->getSetting('timezone_override') ?: $date->getTimezone()->getName(); return $this->dateFormatter->format($date->getTimestamp(), 'custom', $format, $timezone != '' ? $timezone : NULL); diff --git a/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeItem.php b/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeItem.php index 7e01116..d95f2f9 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeItem.php +++ b/core/modules/datetime/src/Plugin/Field/FieldType/DateRangeItem.php @@ -112,9 +112,9 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state '#description' => $this->t('Choose the type of date to create.'), '#default_value' => $this->getSetting('daterange_type'), '#options' => [ - static::DATERANGE_TYPE_DATETIME => t('Date and time'), - static::DATERANGE_TYPE_DATE => t('Date only'), - static::DATERANGE_TYPE_ALLDAY => t('All Day'), + static::DATERANGE_TYPE_DATETIME => $this->t('Date and time'), + static::DATERANGE_TYPE_DATE => $this->t('Date only'), + static::DATERANGE_TYPE_ALLDAY => $this->t('All Day'), ], '#disabled' => $has_data, ]; diff --git a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDatelistWidget.php b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDatelistWidget.php index f92955c..d538f3b 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDatelistWidget.php +++ b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDatelistWidget.php @@ -23,11 +23,11 @@ class DateRangeDatelistWidget extends DateRangeWidgetBase { * {@inheritdoc} */ public static function defaultSettings() { - return array( + return [ 'increment' => '15', 'date_order' => 'YMD', 'time_type' => '24', - ) + parent::defaultSettings(); + ] + parent::defaultSettings(); } /** @@ -51,24 +51,24 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen switch ($date_order) { default: case 'YMD': - $date_part_order = array('year', 'month', 'day'); + $date_part_order = ['year', 'month', 'day']; break; case 'MDY': - $date_part_order = array('month', 'day', 'year'); + $date_part_order = ['month', 'day', 'year']; break; case 'DMY': - $date_part_order = array('day', 'month', 'year'); + $date_part_order = ['day', 'month', 'year']; break; } switch ($time_type) { case '24': - $date_part_order = array_merge($date_part_order, array('hour', 'minute')); + $date_part_order = array_merge($date_part_order, ['hour', 'minute']); break; case '12': - $date_part_order = array_merge($date_part_order, array('hour', 'minute', 'ampm')); + $date_part_order = array_merge($date_part_order, ['hour', 'minute', 'ampm']); break; case 'none': @@ -96,39 +96,39 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen function settingsForm(array $form, FormStateInterface $form_state) { $element = parent::settingsForm($form, $form_state); - $element['date_order'] = array( + $element['date_order'] = [ '#type' => 'select', - '#title' => t('Date part order'), + '#title' => $this->t('Date part order'), '#default_value' => $this->getSetting('date_order'), - '#options' => array('MDY' => t('Month/Day/Year'), 'DMY' => t('Day/Month/Year'), 'YMD' => t('Year/Month/Day')), - ); + '#options' => ['MDY' => $this->t('Month/Day/Year'), 'DMY' => $this->t('Day/Month/Year'), 'YMD' => $this->t('Year/Month/Day')], + ]; if ($this->getFieldSetting('daterange_type') == DateRangeItem::DATERANGE_TYPE_DATETIME) { - $element['time_type'] = array( + $element['time_type'] = [ '#type' => 'select', - '#title' => t('Time type'), + '#title' => $this->t('Time type'), '#default_value' => $this->getSetting('time_type'), - '#options' => array('24' => t('24 hour time'), '12' => t('12 hour time')), - ); + '#options' => ['24' => $this->t('24 hour time'), '12' => $this->t('12 hour time')], + ]; $element['increment'] = [ '#type' => 'select', - '#title' => t('Time increments'), + '#title' => $this->t('Time increments'), '#default_value' => $this->getSetting('increment'), '#options' => [ - 1 => t('1 minute'), - 5 => t('5 minute'), - 10 => t('10 minute'), - 15 => t('15 minute'), - 30 => t('30 minute'), + 1 => $this->t('1 minute'), + 5 => $this->t('5 minute'), + 10 => $this->t('10 minute'), + 15 => $this->t('15 minute'), + 30 => $this->t('30 minute'), ], ]; } else { - $element['time_type'] = array( + $element['time_type'] = [ '#type' => 'hidden', '#value' => 'none', - ); + ]; $element['increment'] = [ '#type' => 'hidden', @@ -143,12 +143,12 @@ function settingsForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function settingsSummary() { - $summary = array(); + $summary = []; - $summary[] = t('Date part order: @order', array('@order' => $this->getSetting('date_order'))); + $summary[] = $this->t('Date part order: @order', ['@order' => $this->getSetting('date_order')]); if ($this->getFieldSetting('daterange_type') == DateRangeItem::DATERANGE_TYPE_DATETIME) { - $summary[] = t('Time type: @time_type', array('@time_type' => $this->getSetting('time_type'))); - $summary[] = t('Time increments: @increment', array('@increment' => $this->getSetting('increment'))); + $summary[] = $this->t('Time type: @time_type', ['@time_type' => $this->getSetting('time_type')]); + $summary[] = $this->t('Time increments: @increment', ['@increment' => $this->getSetting('increment')]); } return $summary; diff --git a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDefaultWidget.php b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDefaultWidget.php index 24af1ce..7d5cb8c 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDefaultWidget.php +++ b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDefaultWidget.php @@ -49,7 +49,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration['field_definition'], $configuration['settings'], $configuration['third_party_settings'], - $container->get('entity.manager')->getStorage('date_format') + $container->get('entity_type.manager')->getStorage('date_format') ); } @@ -83,23 +83,23 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen break; } - $element['value'] += array( + $element['value'] += [ '#date_date_format' => $date_format, '#date_date_element' => $date_type, - '#date_date_callbacks' => array(), + '#date_date_callbacks' => [], '#date_time_format' => $time_format, '#date_time_element' => $time_type, - '#date_time_callbacks' => array(), - ); + '#date_time_callbacks' => [], + ]; - $element['value2'] += array( + $element['value2'] += [ '#date_date_format' => $date_format, '#date_date_element' => $date_type, - '#date_date_callbacks' => array(), + '#date_date_callbacks' => [], '#date_time_format' => $time_format, '#date_time_element' => $time_type, - '#date_time_callbacks' => array(), - ); + '#date_time_callbacks' => [], + ]; return $element; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php index 7d4013d..d8349be 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php +++ b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php @@ -27,23 +27,23 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $element['#attributes']['class'][] = 'container-inline'; $element['#element_validate'][] = [$this, 'validateStartEnd']; - $element['value'] = array( + $element['value'] = [ '#title' => $this->t('Start'), '#type' => 'datetime', '#default_value' => NULL, '#date_increment' => 1, '#date_timezone' => drupal_get_user_timezone(), '#required' => $element['#required'], - ); + ]; - $element['value2'] = array( + $element['value2'] = [ '#title' => $this->t('End'), '#type' => 'datetime', '#default_value' => NULL, '#date_increment' => 1, '#date_timezone' => drupal_get_user_timezone(), '#required' => $element['#required'], - ); + ]; if ($this->getFieldSetting('daterange_type') == DateRangeItem::DATERANGE_TYPE_DATE) { // A date-only field should have no timezone conversion performed, so @@ -156,16 +156,21 @@ public function massageFormValues(array $values, array $form, FormStateInterface } /** - * Validates that the start <= the end date. + * #element_validate callback to ensure that the start date <= the end date. + * + * @param array $element + * An associative array containing the properties and children of the + * generic form element. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + * @param array $complete_form + * The complete form structure. */ - public function validateStartEnd($element, FormStateInterface $form_state) { + public function validateStartEnd(&$element, FormStateInterface $form_state, &$complete_form) { $start_date = $element['value']['#value']['object']; $end_date = $element['value2']['#value']['object']; if ($start_date instanceof DrupalDateTime && $end_date instanceof DrupalDateTime) { - /** @var \Drupal\Core\Datetime\DrupalDateTime $start_date */ - /** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */ - if ($start_date->format('U') !== $end_date->format('U')) { $interval = $start_date->diff($end_date); if ($interval->invert === 1) { diff --git a/core/modules/datetime/src/Tests/DateRangeFieldTest.php b/core/modules/datetime/src/Tests/DateRangeFieldTest.php index f2e4f90..7e90d90 100644 --- a/core/modules/datetime/src/Tests/DateRangeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateRangeFieldTest.php @@ -3,7 +3,6 @@ namespace Drupal\datetime\Tests; use Drupal\Component\Render\FormattableMarkup; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Unicode; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Datetime\Entity\DateFormat; @@ -78,6 +77,13 @@ class DateRangeFieldTest extends WebTestBase { ]; /** + * The date formatter service. + * + * @var \Drupal\Core\Datetime\DateFormatterInterface + */ + protected $dateFormatter; + + /** * {@inheritdoc} */ protected function setUp() { @@ -128,6 +134,8 @@ protected function setUp() { entity_get_display($this->field->getTargetEntityTypeId(), $this->field->getTargetBundle(), 'full') ->setComponent($field_name, $this->displayOptions) ->save(); + + $this->dateFormatter = \Drupal::service('date.formatter'); } /** @@ -212,17 +220,17 @@ public function testDateRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); - $start_expected = format_date($start_date->getTimestamp(), 'long', '', DATETIME_STORAGE_TIMEZONE); - $start_expected_iso = format_date($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE); - $end_expected = format_date($end_date->getTimestamp(), 'long', '', DATETIME_STORAGE_TIMEZONE); - $end_expected_iso = format_date($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE); + $start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long', '', DATETIME_STORAGE_TIMEZONE); + $start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE); + $end_expected = $this->dateFormatter->format($end_date->getTimestamp(), 'long', '', DATETIME_STORAGE_TIMEZONE); + $end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DATETIME_STORAGE_TIMEZONE); $this->renderTestEntity($id); - $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [ + $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [ '%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso ])); - $this->assertFieldByXPath('//time[@datetime="' . $end_expected_iso . '"]', $end_expected, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [ + $this->assertFieldByXPath('//time[@datetime="' . $end_expected_iso . '"]', $end_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', [ '%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso @@ -237,7 +245,7 @@ public function testDateRangeField() { ->save(); $expected = $start_date->format(DATETIME_DATE_STORAGE_FORMAT) . ' - ' . $end_date->format(DATETIME_DATE_STORAGE_FORMAT); $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using plain format displayed as %expected.', array('%expected' => $expected))); + $this->assertText($expected, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', array('%expected' => $expected))); // Verify that the custom formatter works. $this->displayOptions['type'] = 'daterange_custom'; @@ -247,7 +255,7 @@ public function testDateRangeField() { ->save(); $expected = $start_date->format($this->displayOptions['settings']['date_format']) . ' - ' . $end_date->format($this->displayOptions['settings']['date_format']); $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using daterange_custom format displayed as %expected.', array('%expected' => $expected))); + $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', array('%expected' => $expected))); } } @@ -306,13 +314,13 @@ public function testDatetimeRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); - $start_expected = format_date($start_date->getTimestamp(), 'long'); - $start_expected_iso = format_date($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); - $end_expected = format_date($end_date->getTimestamp(), 'long'); - $end_expected_iso = format_date($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); + $start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long'); + $start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); + $end_expected = $this->dateFormatter->format($end_date->getTimestamp(), 'long'); + $end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); $this->renderTestEntity($id); - $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); - $this->assertFieldByXPath('//time[@datetime="' . $end_expected_iso . '"]', $end_expected, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso])); + $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); + $this->assertFieldByXPath('//time[@datetime="' . $end_expected_iso . '"]', $end_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso])); $this->assertText(' THESEPARATOR ', 'Found proper separator'); // Verify that the plain formatter works. @@ -323,7 +331,7 @@ public function testDatetimeRangeField() { ->save(); $expected = $start_date->format(DATETIME_DATETIME_STORAGE_FORMAT) . ' - ' . $end_date->format(DATETIME_DATETIME_STORAGE_FORMAT); $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using plain format displayed as %expected.', array('%expected' => $expected))); + $this->assertText($expected, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', array('%expected' => $expected))); // Verify that the 'datetime_custom' formatter works. $this->displayOptions['type'] = 'daterange_custom'; @@ -333,7 +341,7 @@ public function testDatetimeRangeField() { ->save(); $expected = $start_date->format($this->displayOptions['settings']['date_format']) . ' - ' . $end_date->format($this->displayOptions['settings']['date_format']); $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using daterange_custom format displayed as %expected.', array('%expected' => $expected))); + $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', array('%expected' => $expected))); // Verify that the 'timezone_override' setting works. $this->displayOptions['type'] = 'daterange_custom'; @@ -344,7 +352,7 @@ public function testDatetimeRangeField() { $expected = $start_date->format($this->displayOptions['settings']['date_format'], ['timezone' => 'America/New_York']); $expected .= ' - ' . $end_date->format($this->displayOptions['settings']['date_format'], ['timezone' => 'America/New_York']); $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using daterange_custom format displayed as %expected.', array('%expected' => $expected))); + $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', array('%expected' => $expected))); } /** @@ -397,13 +405,13 @@ public function testAlldayRangeField() { ->setComponent($field_name, $this->displayOptions) ->save(); - $start_expected = format_date($start_date->getTimestamp(), 'long'); - $start_expected_iso = format_date($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); - $end_expected = format_date($end_date->getTimestamp(), 'long'); - $end_expected_iso = format_date($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); + $start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long'); + $start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); + $end_expected = $this->dateFormatter->format($end_date->getTimestamp(), 'long'); + $end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC'); $this->renderTestEntity($id); - $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); - $this->assertFieldByXPath('//time[@datetime="' . $end_expected_iso . '"]', $end_expected, SafeMarkup::format('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso])); + $this->assertFieldByXPath('//time[@datetime="' . $start_expected_iso . '"]', $start_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $start_expected, '%expected_iso' => $start_expected_iso])); + $this->assertFieldByXPath('//time[@datetime="' . $end_expected_iso . '"]', $end_expected, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => 'long', '%expected' => $end_expected, '%expected_iso' => $end_expected_iso])); $this->assertText(' THESEPARATOR ', 'Found proper separator'); // Verify that the plain formatter works. @@ -414,7 +422,7 @@ public function testAlldayRangeField() { ->save(); $expected = $start_date->format(DATETIME_DATETIME_STORAGE_FORMAT) . ' - ' . $end_date->format(DATETIME_DATETIME_STORAGE_FORMAT); $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using plain format displayed as %expected.', array('%expected' => $expected))); + $this->assertText($expected, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', array('%expected' => $expected))); // Verify that the custom formatter works. $this->displayOptions['type'] = 'daterange_custom'; @@ -424,7 +432,7 @@ public function testAlldayRangeField() { ->save(); $expected = $start_date->format($this->displayOptions['settings']['date_format']) . ' - ' . $end_date->format($this->displayOptions['settings']['date_format']); $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using daterange_custom format displayed as %expected.', array('%expected' => $expected))); + $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', array('%expected' => $expected))); // Verify that the 'timezone_override' setting works. $this->displayOptions['type'] = 'daterange_custom'; @@ -435,7 +443,7 @@ public function testAlldayRangeField() { $expected = $start_date->format($this->displayOptions['settings']['date_format'], ['timezone' => 'America/New_York']); $expected .= ' - ' . $end_date->format($this->displayOptions['settings']['date_format'], ['timezone' => 'America/New_York']); $this->renderTestEntity($id); - $this->assertText($expected, SafeMarkup::format('Formatted date field using daterange_custom format displayed as %expected.', array('%expected' => $expected))); + $this->assertText($expected, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected.', array('%expected' => $expected))); } /** @@ -938,7 +946,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => '12:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid start year value %date has been caught.', ['%date' => $date_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid start year value %date has been caught.', ['%date' => $date_value])); $date_value = '2012-75-01'; $edit = [ @@ -948,7 +956,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => '12:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid start month value %date has been caught.', ['%date' => $date_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid start month value %date has been caught.', ['%date' => $date_value])); $date_value = '2012-12-99'; $edit = [ @@ -958,7 +966,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => '12:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid start day value %date has been caught.', ['%date' => $date_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid start day value %date has been caught.', ['%date' => $date_value])); // Submit invalid start times and ensure they is not accepted. $time_value = ''; @@ -979,7 +987,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => '12:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid start hour value %time has been caught.', ['%time' => $time_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid start hour value %time has been caught.', ['%time' => $time_value])); $time_value = '12:99:00'; $edit = [ @@ -989,7 +997,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => '12:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid start minute value %time has been caught.', ['%time' => $time_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid start minute value %time has been caught.', ['%time' => $time_value])); $time_value = '12:15:99'; $edit = [ @@ -999,7 +1007,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => '12:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid start second value %time has been caught.', ['%time' => $time_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid start second value %time has been caught.', ['%time' => $time_value])); // Submit invalid end dates and ensure they is not accepted. $date_value = ''; @@ -1020,7 +1028,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => '00:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid end year value %date has been caught.', ['%date' => $date_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid end year value %date has been caught.', ['%date' => $date_value])); $date_value = '2012-75-01'; $edit = [ @@ -1030,7 +1038,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => '00:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid end month value %date has been caught.', ['%date' => $date_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid end month value %date has been caught.', ['%date' => $date_value])); $date_value = '2012-12-99'; $edit = [ @@ -1040,7 +1048,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => '00:00:00', ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid end day value %date has been caught.', ['%date' => $date_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid end day value %date has been caught.', ['%date' => $date_value])); // Submit invalid start times and ensure they is not accepted. $time_value = ''; @@ -1061,7 +1069,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => $time_value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid end hour value %time has been caught.', ['%time' => $time_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid end hour value %time has been caught.', ['%time' => $time_value])); $time_value = '12:99:00'; $edit = [ @@ -1071,7 +1079,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => $time_value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid end minute value %time has been caught.', ['%time' => $time_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid end minute value %time has been caught.', ['%time' => $time_value])); $time_value = '12:15:99'; $edit = [ @@ -1081,7 +1089,7 @@ public function testInvalidField() { "{$field_name}[0][value2][time]" => $time_value, ]; $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertText('date is invalid', format_string('Invalid end second value %time has been caught.', ['%time' => $time_value])); + $this->assertText('date is invalid', new FormattableMarkup('Invalid end second value %time has been caught.', ['%time' => $time_value])); $edit = [ "{$field_name}[0][value][date]" => '2012-12-01',