diff -r -u drupal-8.x-new/core/includes/common.inc drupal-8.x/core/includes/common.inc --- drupal-8.x-new/core/includes/common.inc Thu Mar 7 16:43:44 2013 +++ drupal-8.x/core/includes/common.inc Thu Mar 7 18:17:36 2013 @@ -1899,7 +1899,18 @@ 'langcode' => $langcode, 'format_string_type' => $key, ); - return filter_xss_admin($date->format($format, $settings)); + + $formatted_date = $date->format($format, $settings); + + $context = array( + 'date_time' => $date, + 'type' => $type, + 'format' => $format, + 'langcode' => $langcode, + ); + drupal_alter('format_date', $formatted_date, $context); + + return filter_xss_admin($formatted_date); } /** diff -r -u drupal-8.x-new/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php drupal-8.x/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php --- drupal-8.x-new/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php Thu Mar 7 16:43:44 2013 +++ drupal-8.x/core/modules/system/lib/Drupal/system/Tests/Datetime/DrupalDateTimeTest.php Thu Mar 7 18:13:34 2013 @@ -26,7 +26,7 @@ /** * Set up required modules. */ - public static $modules = array(); + public static $modules = array('system_test'); /** * Test setup. @@ -108,5 +108,30 @@ drupal_save_session(TRUE); + } + + /** + * Test hook_format_date_alter() function and format_date() function. + */ + function testFormatDate() { + // Setup date/time settings for Honolulu time. + $config = config('system.timezone') + ->set('default', 'Pacific/Honolulu') + ->set('user.configurable', 0) + ->save(); + $config = config('system.date') + ->set('formats.medium.pattern.php', 'Y-m-d H:i:s O') + ->save(); + // Create some nodes with different authored-on dates. + $date1 = '2007-01-31 21:00:00 -1000'; + $date2 = '2007-07-31 21:00:00 -1000'; + $node1 = $this->drupalCreateNode(array('created' => strtotime($date1), 'type' => 'article')); + $node2 = $this->drupalCreateNode(array('created' => strtotime($date2), 'type' => 'article')); + + // Confirm date format was changed by implemented hook function. + $this->drupalGet("node/$node1->nid"); + $this->assertText('0001- 00:00:12 13-10-7002', 'Date was reversed successfully.'); + $this->drupalGet("node/$node2->nid"); + $this->assertText('0001- 00:00:12 13-70-7002', 'Date was reversed successfully.'); } } diff -r -u drupal-8.x-new/core/modules/system/system.api.php drupal-8.x/core/modules/system/system.api.php --- drupal-8.x-new/core/modules/system/system.api.php Thu Mar 7 16:43:44 2013 +++ drupal-8.x/core/modules/system/system.api.php Thu Mar 7 18:13:34 2013 @@ -3652,6 +3652,29 @@ } /** + * Alter the formatted date. + * + * A module may implement this hook in order to alter the formatted date string. + * + * @param string $formatted_date + * The formatted date. + * @param array $context + * An associative array containing: + * - date_time: The DrupalDateTime object with the date to format. + * - type: The format to use as passed to format_date(). + * - format: If type is 'custom', a PHP date format string suitable for input + * to date(). + * - langcode: The language code as passed to format_date(). + * + * @see format_date() + */ +function hook_format_date_alter(&$formatted_date, array $context) { + $formatted_date .= ' ' . $context['type']; +} + + + +/** * @} End of "addtogroup hooks". */ Only in drupal-8.x/core/modules/system: system.api.php.orig diff -r -u drupal-8.x-new/core/modules/system/tests/modules/system_test/system_test.module drupal-8.x/core/modules/system/tests/modules/system_test/system_test.module --- drupal-8.x-new/core/modules/system/tests/modules/system_test/system_test.module Thu Mar 7 16:43:44 2013 +++ drupal-8.x/core/modules/system/tests/modules/system_test/system_test.module Thu Mar 7 18:13:34 2013 @@ -380,3 +380,11 @@ system_authorized_init('system_test_authorize_run', drupal_get_path('module', 'system_test') . '/system_test.module', array(), $page_title); drupal_goto($authorize_url); } + +/** + * Implements hook_format_date_alter(). + */ +function system_test_format_date_alter(&$formatted_date, array $context) { + // Reverse the date string for testing purpose. + $formatted_date = strrev($formatted_date); +} Only in drupal-8.x/core/modules/system/tests/modules/system_test: system_test.module.orig