diff --git a/core/modules/datetime/config/schema/datetime.schema.yml b/core/modules/datetime/config/schema/datetime.schema.yml index 0718e04..72f8067 100644 --- a/core/modules/datetime/config/schema/datetime.schema.yml +++ b/core/modules/datetime/config/schema/datetime.schema.yml @@ -30,10 +30,56 @@ field.formatter.settings.datetime_default: format_type: type: string label: 'Date format' + timezone_override: + type: string + label: 'Timezone override' + append_timezone: + type: boolean + label: 'Append timezone' field.formatter.settings.datetime_plain: type: mapping label: 'Datetime plain display format settings' + mapping: + timezone_override: + type: string + label: 'Timezone override' + append_timezone: + type: boolean + label: 'Append timezone' + +field.formatter.settings.datetime_custom: + type: mapping + label: 'Datetime plain display format settings' + mapping: + timezone_override: + type: string + label: 'Timezone override' + append_timezone: + type: boolean + label: 'Append timezone' + date_format: + type: string + label: 'Format string' + translatable: true + translation context: 'PHP date format' + +field.formatter.settings.datetime_time_ago: + type: mapping + label: 'Datetime time ago display format settings' + mapping: + timezone_override: + type: string + label: 'Timezone override' + append_timezone: + type: boolean + label: 'Append timezone' + format_type: + type: string + label: 'Date format' + granularity: + type: integer + label: 'Granularity' field.widget.settings.datetime_datelist: type: mapping diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php new file mode 100644 index 0000000..a2d5f6b --- /dev/null +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php @@ -0,0 +1,82 @@ + DATETIME_DATETIME_STORAGE_FORMAT, + ) + parent::defaultSettings(); + } + + /** + * {@inheritdoc} + */ + public function viewElements(FieldItemListInterface $items) { + $elements = array(); + + foreach ($items as $delta => $item) { + $output = ''; + if (!empty($item->date)) { + $date = $item->date; + $this->setTimeZone($date); + $output = $date->format($this->getSetting('date_format')); + } + $elements[$delta] = array('#markup' => $this->appendTimezone($output)); + } + + return $elements; + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, FormStateInterface $form_state) { + $elements = parent::settingsForm($form, $form_state); + + $elements['date_format'] = array( + '#type' => 'textfield', + '#title' => $this->t('Format string'), + '#description' => $this->t('A user-defined date format. See the PHP manual for available options.', array('@url' => 'http://php.net/manual/function.date.php')), + '#default_value' => $this->getSetting('date_format'), + ); + + return $elements; + } + + /** + * {@inheritdoc} + */ + public function settingsSummary() { + $summary = parent::settingsSummary(); + $date = new DrupalDateTime(); + $this->setTimeZone($date); + $summary[] = $this->appendTimezone($date->format($this->getSetting('date_format'))); + return $summary; + } + +} diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php index a7cb32a..353ea0b 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php @@ -14,11 +14,10 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Field\FormatterBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Plugin implementation of the 'datetime_default' formatter. + * Plugin implementation of the 'Default' formatter for 'datetime' fields. * * @FieldFormatter( * id = "datetime_default", @@ -28,7 +27,7 @@ * } * ) */ -class DateTimeDefaultFormatter extends FormatterBase implements ContainerFactoryPluginInterface { +class DateTimeDefaultFormatter extends DateTimeFormatterBase implements ContainerFactoryPluginInterface { /** * {@inheritdoc} @@ -103,11 +102,9 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items) { - $elements = array(); foreach ($items as $delta => $item) { - $formatted_date = ''; $iso_date = ''; @@ -116,13 +113,11 @@ public function viewElements(FieldItemListInterface $items) { // Create the ISO date in Universal Time. $iso_date = $date->format("Y-m-d\TH:i:s") . 'Z'; - // The formatted output will be in local time. - $date->setTimeZone(timezone_open(drupal_get_user_timezone())); if ($this->getFieldSetting('datetime_type') == 'date') { // A date without time will pick up the current time, use the default. datetime_date_default_time($date); } - $formatted_date = $this->dateFormat($date); + $formatted_date = $this->formatDate($date); } // Display the date using theme datetime. @@ -160,15 +155,19 @@ public function viewElements(FieldItemListInterface $items) { * @return string * A formatted date string using the chosen format. */ - function dateFormat($date) { + function formatDate($date) { $format_type = $this->getSetting('format_type'); - return $this->dateFormatter->format($date->getTimestamp(), $format_type); + $timezone = $this->getSetting('timezone_override'); + $output = $this->dateFormatter->format($date->getTimestamp(), $format_type, '', $timezone != '' ? $timezone : null); + return $this->appendTimezone($output); } /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { + $elements = parent::settingsForm($form, $form_state); + $time = new DrupalDateTime(); $format_types = $this->dateStorage->loadMultiple(); foreach ($format_types as $type => $type_info) { @@ -191,9 +190,9 @@ public function settingsForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function settingsSummary() { - $summary = array(); + $summary = parent::settingsSummary(); $date = new DrupalDateTime(); - $summary[] = t('Format: @display', array('@display' => $this->dateFormat($date, FALSE))); + $summary[] = t('Format: @display', array('@display' => $this->appendTimezone($this->formatDate($date)))); return $summary; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php new file mode 100644 index 0000000..bee1454 --- /dev/null +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeFormatterBase.php @@ -0,0 +1,105 @@ + '', + 'append_timezone' => FALSE, + ) + parent::defaultSettings(); + } + + /** + * {@inheritdoc} + */ + public function settingsForm(array $form, FormStateInterface $form_state) { + $elements['timezone_override'] = array( + '#type' => 'select', + '#title' => $this->t('Timezone override'), + '#description' => $this->t('Always use the selected timezone'), + '#options' => system_time_zones(TRUE), + '#default_value' => $this->getSetting('timezone_override'), + ); + + $elements['append_timezone'] = array( + '#type' => 'checkbox', + '#title' => $this->t('Append timezone'), + '#description' => $this->t('Append the timezone used to render the date'), + '#default_value' => $this->getSetting('append_timezone'), + ); + + return $elements; + } + + /** + * {@inheritdoc} + */ + public function settingsSummary() { + $summary = array(); + $override = $this->getSetting('timezone_override'); + if ($override != '') { + $replacements = array( + '@timezone' => $this->getSetting('timezone_override'), + '@appended' => $this->getSetting('append_timezone') ? $this->t('(Appended)') : '', + ); + $summary[] = $override != '' ? $this->t('Timezone: @timezone @appended', $replacements) : ''; + } + return $summary; + } + + /** + * Sets the current user's or overridden timezone on a date. + * + * @param \Drupal\Core\Datetime\DrupalDateTime $date + * A date object. + */ + protected function setTimeZone(DrupalDateTime $date) { + if ($this->getSetting('timezone_override') == '') { + $date->setTimeZone(timezone_open(drupal_get_user_timezone())); + } + else{ + $date->setTimezone(timezone_open($this->getSetting('timezone_override'))); + } + } + + /** + * Appends the timezone used to render the date. + * + * @param string $rendered_date + * A formatted date string. + * + * @return string + * A formatted date string with the timezone appended. + */ + protected function appendTimezone($rendered_date) { + $timezone = $this->getSetting('timezone_override'); + if ($timezone != '' && $this->getSetting('append_timezone')) { + return SafeMarkup::format('@rendered_date (@timezone)', array( + '@rendered_date' => $rendered_date, + '@timezone' => $timezone, + )); + } + else { + return $rendered_date; + } + } + +} diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php index 3f68a7f..7550756 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php @@ -7,11 +7,10 @@ namespace Drupal\datetime\Plugin\Field\FieldFormatter; -use Drupal\Core\Field\FormatterBase; use Drupal\Core\Field\FieldItemListInterface; /** - * Plugin implementation of the 'datetime_plain' formatter. + * Plugin implementation of the 'Plain' formatter for 'datetime' fields. * * @FieldFormatter( * id = "datetime_plain", @@ -21,23 +20,20 @@ * } *) */ -class DateTimePlainFormatter extends FormatterBase { +class DateTimePlainFormatter extends DateTimeFormatterBase { /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items) { - $elements = array(); foreach ($items as $delta => $item) { - $output = ''; if (!empty($item->date)) { - // The date was created and verified during field_load(), so it is safe - // to use without further inspection. $date = $item->date; - $date->setTimeZone(timezone_open(drupal_get_user_timezone())); + $this->setTimeZone($date); + $format = DATETIME_DATETIME_STORAGE_FORMAT; if ($this->getFieldSetting('datetime_type') == 'date') { // A date without time will pick up the current time, use the default. @@ -52,7 +48,7 @@ public function viewElements(FieldItemListInterface $items) { 'timezone', ], ], - '#markup' => $output, + '#markup' => $this->appendTimezone($output), ]; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php similarity index 55% copy from core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php copy to core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php index a7cb32a..b62b56e 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeTimeAgoFormatter.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeDefaultFormatter. + * Contains \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeTimeAgoFormatter. */ namespace Drupal\datetime\Plugin\Field\FieldFormatter; @@ -14,30 +14,20 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Field\FormatterBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Plugin implementation of the 'datetime_default' formatter. + * Plugin implementation of the 'Time ago' formatter for 'datetime' fields. * * @FieldFormatter( - * id = "datetime_default", - * label = @Translation("Default"), + * id = "datetime_time_ago", + * label = @Translation("Time ago"), * field_types = { * "datetime" * } * ) */ -class DateTimeDefaultFormatter extends FormatterBase implements ContainerFactoryPluginInterface { - - /** - * {@inheritdoc} - */ - public static function defaultSettings() { - return array( - 'format_type' => 'medium', - ) + parent::defaultSettings(); - } +class DateTimeTimeAgoFormatter extends DateTimeFormatterBase implements ContainerFactoryPluginInterface { /** * The date formatter service. @@ -54,7 +44,7 @@ public static function defaultSettings() { protected $dateStorage; /** - * Constructs a new DateTimeDefaultFormatter. + * Constructs a DateTimeTimeAgoFormatter object. * * @param string $plugin_id * The plugin_id for the formatter. @@ -85,6 +75,16 @@ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInter /** * {@inheritdoc} */ + public static function defaultSettings() { + return array( + 'format_type' => 'time span', + 'granularity' => 2, + ) + parent::defaultSettings(); + } + + /** + * {@inheritdoc} + */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $plugin_id, @@ -103,48 +103,15 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items) { - $elements = array(); foreach ($items as $delta => $item) { - - $formatted_date = ''; - $iso_date = ''; - - if ($item->date) { - $date = $item->date; - // Create the ISO date in Universal Time. - $iso_date = $date->format("Y-m-d\TH:i:s") . 'Z'; - - // The formatted output will be in local time. - $date->setTimeZone(timezone_open(drupal_get_user_timezone())); - if ($this->getFieldSetting('datetime_type') == 'date') { - // A date without time will pick up the current time, use the default. - datetime_date_default_time($date); - } - $formatted_date = $this->dateFormat($date); - } - - // Display the date using theme datetime. - $elements[$delta] = array( - '#cache' => [ - 'contexts' => [ - 'timezone', - ], - ], - '#theme' => 'time', - '#text' => $formatted_date, - '#html' => FALSE, - '#attributes' => array( - 'datetime' => $iso_date, - ), - ); - if (!empty($item->_attributes)) { - $elements[$delta]['#attributes'] += $item->_attributes; - // Unset field item attributes since they have been included in the - // formatter output and should not be rendered in the field template. - unset($item->_attributes); + $date = $item->date; + $output = ''; + if (!empty($item->date)) { + $output = $this->formatDate($date); } + $elements[$delta] = array('#markup' => $output); } return $elements; @@ -152,23 +119,11 @@ public function viewElements(FieldItemListInterface $items) { } /** - * Creates a formatted date value as a string. - * - * @param object $date - * A date object. - * - * @return string - * A formatted date string using the chosen format. - */ - function dateFormat($date) { - $format_type = $this->getSetting('format_type'); - return $this->dateFormatter->format($date->getTimestamp(), $format_type); - } - - /** * {@inheritdoc} */ public function settingsForm(array $form, FormStateInterface $form_state) { + $elements = parent::settingsForm($form, $form_state); + $time = new DrupalDateTime(); $format_types = $this->dateStorage->loadMultiple(); foreach ($format_types as $type => $type_info) { @@ -178,12 +133,26 @@ public function settingsForm(array $form, FormStateInterface $form_state) { $elements['format_type'] = array( '#type' => 'select', - '#title' => t('Date format'), - '#description' => t("Choose a format for displaying the date. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date."), - '#options' => $options, + '#title' => $this->t('Date format'), + '#options' => array( + 'raw time ago' => $this->t('Time ago'), + 'time ago' => $this->t('Time ago (with "ago" appended)'), + 'raw time hence' => $this->t('Time hence'), + 'time hence' => $this->t('Time hence (with "hence" appended)'), + 'raw time span' => $this->t('Time span (future dates have "-" prepended)'), + 'inverse time span' => $this->t('Time span (past dates have "-" prepended)'), + 'time span' => $this->t('Time span (with "ago/hence" appended)'), + ), '#default_value' => $this->getSetting('format_type'), ); + $elements['granularity'] = array( + '#type' => 'number', + '#title' => 'Interval', + '#default_value' => $this->getSetting('granularity'), + '#description' => $this->t('How many time units should be shown in the \'time ago\' string.'), + ); + return $elements; } @@ -191,10 +160,41 @@ public function settingsForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function settingsSummary() { - $summary = array(); - $date = new DrupalDateTime(); - $summary[] = t('Format: @display', array('@display' => $this->dateFormat($date, FALSE))); + $future_date = new DrupalDateTime('1 year 1 month 1 week 1 day 1 hour 1 minute'); + $past_date = new DrupalDateTime('-1 year'); + $summary[] = t('Future date: !display', array('!display' => $this->formatDate($future_date))); + $summary[] = t('Past date: !display', array('!display' => $this->formatDate($past_date))); return $summary; } + /** + * Creates a formatted date value as a string. + * + * @param \Drupal\Core\Datetime\DrupalDateTime|object $date + * A date object. + * @return string + * A formatted date string using the chosen format. + */ + protected function formatDate(DrupalDateTime $date) { + $format = $this->getSetting('format_type'); + $granularity = $this->getSetting('granularity'); + $interval = REQUEST_TIME - $date->getTimestamp(); + switch ($format) { + case 'time ago': + return $this->t('%time ago', array('%time' => $this->dateFormatter->formatInterval($interval, $granularity))); + case 'raw time hence': + return $this->dateFormatter->formatInterval(-$interval, $granularity); + case 'time hence': + return $this->t('%time hence', array('%time' => $this->dateFormatter->formatInterval(-$interval, $granularity))); + case 'raw time span': + return ($interval < 0 ? '-' : '') . $this->dateFormatter->formatInterval(abs($interval), $granularity); + case 'inverse time span': + return ($interval > 0 ? '-' : '') . $this->dateFormatter->formatInterval(abs($interval), $granularity); + case 'time span': + return $this->t(($interval < 0 ? '%time hence' : '%time ago'), array('%time' => $this->dateFormatter->formatInterval(abs($interval), $granularity))); + default: // Fallback to raw time ago. + return $this->dateFormatter->formatInterval($interval, $granularity); + } + } + } diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php index e2223dc..88f42c9 100644 --- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php @@ -155,6 +155,33 @@ function testDateField() { $expected = $date->format(DATETIME_DATE_STORAGE_FORMAT); $this->renderTestEntity($id); $this->assertText($expected, format_string('Formatted date field using plain format displayed as %expected.', array('%expected' => $expected))); + + // Verify that the 'datetime_custom' formatter works. + $this->displayOptions['type'] = 'datetime_custom'; + $this->displayOptions['settings'] = array('date_format' => 'm/d/Y'); + entity_get_display($this->field->entity_type, $this->field->bundle, 'full') + ->setComponent($field_name, $this->displayOptions) + ->save(); + $expected = $date->format($this->displayOptions['settings']['date_format']); + $this->renderTestEntity($id); + $this->assertText($expected, format_string('Formatted date field using datetime_custom format displayed as %expected.', array('%expected' => $expected))); + + // Verify that the 'datetime_time_ago' formatter works. First update the + // test entity so that the date difference always has the same interval. + $entity = entity_load('entity_test', $id); + $field_name = $this->fieldStorage->getName(); + $date = DrupalDateTime::createFromTimestamp(REQUEST_TIME - 87654321); + $entity->{$field_name}->value = $date->format($date_format); + $entity->save(); + + $this->displayOptions['type'] = 'datetime_time_ago'; + $this->displayOptions['settings'] = array('format_type' => 'time ago', 'granularity' => 3); + entity_get_display($this->field->entity_type, $this->field->bundle, 'full') + ->setComponent($field_name, $this->displayOptions) + ->save(); + $expected = '2 years 9 months 2 weeks ago'; + $this->renderTestEntity($id); + $this->assertText($expected, format_string('Formatted date field using datetime_time_ago format displayed as %expected.', array('%expected' => $expected))); } /** @@ -221,6 +248,33 @@ function testDatetimeField() { $expected = $date->format(DATETIME_DATETIME_STORAGE_FORMAT); $this->renderTestEntity($id); $this->assertText($expected, format_string('Formatted date field using plain format displayed as %expected.', array('%expected' => $expected))); + + // Verify that the 'datetime_custom' formatter works. + $this->displayOptions['type'] = 'datetime_custom'; + $this->displayOptions['settings'] = array('date_format' => 'm/d/Y g:i:s A'); + entity_get_display($this->field->entity_type, $this->field->bundle, 'full') + ->setComponent($field_name, $this->displayOptions) + ->save(); + $expected = $date->format($this->displayOptions['settings']['date_format']); + $this->renderTestEntity($id); + $this->assertText($expected, format_string('Formatted date field using datetime_custom format displayed as %expected.', array('%expected' => $expected))); + + // Verify that the 'datetime_time_ago' formatter works. First update the + // test entity so that the date difference always has the same interval. + $entity = entity_load('entity_test', $id); + $field_name = $this->fieldStorage->getName(); + $date = DrupalDateTime::createFromTimestamp(REQUEST_TIME - 87654321); + $entity->{$field_name}->value = $date->format(DATETIME_DATETIME_STORAGE_FORMAT); + $entity->save(); + + $this->displayOptions['type'] = 'datetime_time_ago'; + $this->displayOptions['settings'] = array('format_type' => 'time ago', 'granularity' => 4); + entity_get_display($this->field->entity_type, $this->field->bundle, 'full') + ->setComponent($field_name, $this->displayOptions) + ->save(); + $expected = '2 years 9 months 2 weeks 12 hours ago'; + $this->renderTestEntity($id); + $this->assertText($expected, format_string('Formatted date field using datetime_time_ago format displayed as %expected.', array('%expected' => $expected))); } /** diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldFormatterSettingsTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldFormatterSettingsTest.php index 2175cb0..6058cce 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldFormatterSettingsTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldFormatterSettingsTest.php @@ -157,79 +157,79 @@ public function testEntityDisplaySettings() { 'target' => '0', ); $component = $display->getComponent('field_test_link'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); $expected['settings']['url_only'] = FALSE; $expected['settings']['url_plain'] = FALSE; $display = entity_load('entity_view_display', 'node.story.teaser'); $component = $display->getComponent('field_test_link'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); // Test the file field formatter settings. $expected['weight'] = 8; $expected['type'] = 'file_default'; $expected['settings'] = array(); $component = $display->getComponent('field_test_filefield'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); $display = entity_load('entity_view_display', 'node.story.default'); $expected['type'] = 'file_url_plain'; $component = $display->getComponent('field_test_filefield'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); // Test the image field formatter settings. $expected['weight'] = 9; $expected['type'] = 'image'; $expected['settings'] = array('image_style' => '', 'image_link' => ''); $component = $display->getComponent('field_test_imagefield'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); $display = entity_load('entity_view_display', 'node.story.teaser'); $expected['settings']['image_link'] = 'file'; $component = $display->getComponent('field_test_imagefield'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); // Test phone field. $expected['weight'] = 13; $expected['type'] = 'basic_string'; $expected['settings'] = array(); $component = $display->getComponent('field_test_phone'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); // Test date field. $expected['weight'] = 10; $expected['type'] = 'datetime_default'; $expected['settings'] = array('format_type' => 'fallback'); $component = $display->getComponent('field_test_date'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); $display = entity_load('entity_view_display', 'node.story.default'); $expected['settings']['format_type'] = 'long'; $component = $display->getComponent('field_test_date'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); // Test date stamp field. $expected['weight'] = 11; $expected['settings']['format_type'] = 'fallback'; $component = $display->getComponent('field_test_datestamp'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); $display = entity_load('entity_view_display', 'node.story.teaser'); $expected['settings'] = array('format_type' => 'medium'); $component = $display->getComponent('field_test_datestamp'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); // Test datetime field. $expected['weight'] = 12; $expected['settings'] = array('format_type' => 'short'); $component = $display->getComponent('field_test_datetime'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); $display = entity_load('entity_view_display', 'node.story.default'); $expected['settings']['format_type'] = 'fallback'; $component = $display->getComponent('field_test_datetime'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); // Test a date field with a random format which should be mapped // to datetime_default. $display = entity_load('entity_view_display', 'node.story.rss'); $expected['settings']['format_type'] = 'fallback'; $component = $display->getComponent('field_test_datetime'); - $this->assertIdentical($expected, $component); + $this->assertEqual(ksort($component), ksort($expected)); // Test that our Id map has the correct data. $this->assertIdentical(array('node', 'story', 'teaser', 'field_test'), entity_load('migration', 'd6_field_formatter_settings')->getIdMap()->lookupDestinationID(array('story', 'teaser', 'node', 'field_test'))); }