Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -7,7 +7,6 @@
namespace Drupal\Core\Datetime;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\EntityManagerInterface;
@ -22,7 +21,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
*
* @ingroup i18n
*/
class DateFormatter {
class DateFormatter implements DateFormatterInterface {
use StringTranslationTrait;
/**
@ -105,33 +104,7 @@ class DateFormatter {
}
/**
* Formats a date, using a date type or a custom date format string.
*
* @param int $timestamp
* A UNIX timestamp to format.
* @param string $type
* (optional) The format to use, one of:
* - One of the built-in formats: 'short', 'medium',
* 'long', 'html_datetime', 'html_date', 'html_time',
* 'html_yearless_date', 'html_week', 'html_month', 'html_year'.
* - The name of a date type defined by a date format config entity.
* - The machine name of an administrator-defined date format.
* - 'custom', to use $format.
* Defaults to 'medium'.
* @param string $format
* (optional) If $type is 'custom', a PHP date format string suitable for
* input to date(). Use a backslash to escape ordinary text, so it does not
* get interpreted as date format characters.
* @param string|null $timezone
* (optional) Time zone identifier, as described at
* http://php.net/manual/timezones.php Defaults to the time zone used to
* display the page.
* @param string|null $langcode
* (optional) Language code to translate to. NULL (default) means to use
* the user interface language for the page.
*
* @return string
* A translated date string in the requested format.
* {@inheritdoc}
*/
public function format($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
if (!isset($timezone)) {
@ -168,32 +141,11 @@ class DateFormatter {
$settings = array(
'langcode' => $langcode,
);
return Xss::filter($date->format($format, $settings));
return $date->format($format, $settings);
}
/**
* Formats a time interval with the requested granularity.
*
* Note that for intervals over 30 days, the output is approximate: a "month"
* is always exactly 30 days, and a "year" is always 365 days. It is not
* possible to make a more exact representation, given that there is only one
* input in seconds. If you are formatting an interval between two specific
* timestamps, use \Drupal\Core\Datetime\DateFormatter::formatDiff() instead.
*
* @param int $interval
* The length of the interval in seconds.
* @param int $granularity
* (optional) How many different units to display in the string (2 by
* default).
* @param string|null $langcode
* (optional) langcode: The language code for the language used to format
* the date. Defaults to NULL, which results in the user interface language
* for the page being used.
*
* @return string
* A translated string representation of the interval.
*
* @see \Drupal\Core\Datetime\DateFormatter::formatDiff()
* {@inheritdoc}
*/
public function formatInterval($interval, $granularity = 2, $langcode = NULL) {
$output = '';
@ -218,21 +170,7 @@ class DateFormatter {
}
/**
* Provides values for all date formatting characters for a given timestamp.
*
* @param string|null $langcode
* (optional) Language code of the date format, if different from the site
* default language.
* @param int|null $timestamp
* (optional) The Unix timestamp to format, defaults to current time.
* @param string|null $timezone
* (optional) The timezone to use, if different from the site's default
* timezone.
*
* @return array
* An array of formatted date values, indexed by the date format character.
*
* @see date()
* {@inheritdoc}
*/
public function getSampleDateFormats($langcode = NULL, $timestamp = NULL, $timezone = NULL) {
$timestamp = $timestamp ?: time();
@ -245,30 +183,7 @@ class DateFormatter {
}
/**
* Formats the time difference from the current request time to a timestamp.
*
* @param $timestamp
* A UNIX timestamp to compare against the current request time.
* @param array $options
* (optional) An associative array with additional options. The following
* keys can be used:
* - granularity: An integer value that signals how many different units to
* display in the string. Defaults to 2.
* - langcode: The language code for the language used to format the date.
* Defaults to NULL, which results in the user interface language for the
* page being used.
* - strict: A Boolean value indicating whether or not the timestamp can be
* before the current request time. If TRUE (default) and $timestamp is
* before the current request time, the result string will be "0 seconds".
* If FALSE and $timestamp is before the current request time, the result
* string will be the formatted time difference.
*
* @return string
* A translated string representation of the difference between the given
* timestamp and the current request time. This interval is always positive.
*
* @see \Drupal\Core\Datetime\DateFormatter::formatDiff()
* @see \Drupal\Core\Datetime\DateFormatter::formatTimeDiffSince()
* {@inheritdoc}
*/
public function formatTimeDiffUntil($timestamp, $options = array()) {
$request_time = $this->requestStack->getCurrentRequest()->server->get('REQUEST_TIME');
@ -276,30 +191,7 @@ class DateFormatter {
}
/**
* Formats the time difference from a timestamp to the current request time.
*
* @param $timestamp
* A UNIX timestamp to compare against the current request time.
* @param array $options
* (optional) An associative array with additional options. The following
* keys can be used:
* - granularity: An integer value that signals how many different units to
* display in the string. Defaults to 2.
* - langcode: The language code for the language used to format the date.
* Defaults to NULL, which results in the user interface language for the
* page being used.
* - strict: A Boolean value indicating whether or not the timestamp can be
* after the current request time. If TRUE (default) and $timestamp is
* after the current request time, the result string will be "0 seconds".
* If FALSE and $timestamp is after the current request time, the result
* string will be the formatted time difference.
*
* @return string
* A translated string representation of the difference between the given
* timestamp and the current request time. This interval is always positive.
*
* @see \Drupal\Core\Datetime\DateFormatter::formatDiff()
* @see \Drupal\Core\Datetime\DateFormatter::formatTimeDiffUntil()
* {@inheritdoc}
*/
public function formatTimeDiffSince($timestamp, $options = array()) {
$request_time = $this->requestStack->getCurrentRequest()->server->get('REQUEST_TIME');
@ -307,32 +199,7 @@ class DateFormatter {
}
/**
* Formats a time interval between two timestamps.
*
* @param int $from
* A UNIX timestamp, defining the from date and time.
* @param int $to
* A UNIX timestamp, defining the to date and time.
* @param array $options
* (optional) An associative array with additional options. The following
* keys can be used:
* - granularity: An integer value that signals how many different units to
* display in the string. Defaults to 2.
* - langcode: The language code for the language used to format the date.
* Defaults to NULL, which results in the user interface language for the
* page being used.
* - strict: A Boolean value indicating whether or not the $from timestamp
* can be after the $to timestamp. If TRUE (default) and $from is after
* $to, the result string will be "0 seconds". If FALSE and $from is
* after $to, the result string will be the formatted time difference.
*
* @return string
* A translated string representation of the interval. This interval is
* always positive.
*
* @see \Drupal\Core\Datetime\DateFormatter::formatInterval()
* @see \Drupal\Core\Datetime\DateFormatter::formatTimeDiffSince()
* @see \Drupal\Core\Datetime\DateFormatter::formatTimeDiffUntil()
* {@inheritdoc}
*/
public function formatDiff($from, $to, $options = array()) {

View file

@ -0,0 +1,178 @@
<?php
/**
* @file
* Contains \Drupal\Core\Datetime\DateFormatterInterface.
*/
namespace Drupal\Core\Datetime;
/**
* Provides an interface defining a date formatter.
*/
interface DateFormatterInterface {
/**
* Formats a date, using a date type or a custom date format string.
*
* @param int $timestamp
* A UNIX timestamp to format.
* @param string $type
* (optional) The format to use, one of:
* - One of the built-in formats: 'short', 'medium',
* 'long', 'html_datetime', 'html_date', 'html_time',
* 'html_yearless_date', 'html_week', 'html_month', 'html_year'.
* - The name of a date type defined by a date format config entity.
* - The machine name of an administrator-defined date format.
* - 'custom', to use $format.
* Defaults to 'medium'.
* @param string $format
* (optional) If $type is 'custom', a PHP date format string suitable for
* input to date(). Use a backslash to escape ordinary text, so it does not
* get interpreted as date format characters.
* @param string|null $timezone
* (optional) Time zone identifier, as described at
* http://php.net/manual/timezones.php Defaults to the time zone used to
* display the page.
* @param string|null $langcode
* (optional) Language code to translate to. NULL (default) means to use
* the user interface language for the page.
*
* @return string
* A translated date string in the requested format. Since the format may
* contain user input, this value should be escaped when output.
*/
public function format($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL);
/**
* Formats a time interval with the requested granularity.
*
* Note that for intervals over 30 days, the output is approximate: a "month"
* is always exactly 30 days, and a "year" is always 365 days. It is not
* possible to make a more exact representation, given that there is only one
* input in seconds. If you are formatting an interval between two specific
* timestamps, use \Drupal\Core\Datetime\DateFormatter::formatDiff() instead.
*
* @param int $interval
* The length of the interval in seconds.
* @param int $granularity
* (optional) How many different units to display in the string (2 by
* default).
* @param string|null $langcode
* (optional) langcode: The language code for the language used to format
* the date. Defaults to NULL, which results in the user interface language
* for the page being used.
*
* @return string
* A translated string representation of the interval.
*
* @see \Drupal\Core\Datetime\DateFormatterInterface::formatDiff()
*/
public function formatInterval($interval, $granularity = 2, $langcode = NULL);
/**
* Provides values for all date formatting characters for a given timestamp.
*
* @param string|null $langcode
* (optional) Language code of the date format, if different from the site
* default language.
* @param int|null $timestamp
* (optional) The Unix timestamp to format, defaults to current time.
* @param string|null $timezone
* (optional) The timezone to use, if different from the site's default
* timezone.
*
* @return array
* An array of formatted date values, indexed by the date format character.
*
* @see date()
*/
public function getSampleDateFormats($langcode = NULL, $timestamp = NULL, $timezone = NULL);
/**
* Formats the time difference from the current request time to a timestamp.
*
* @param $timestamp
* A UNIX timestamp to compare against the current request time.
* @param array $options
* (optional) An associative array with additional options. The following
* keys can be used:
* - granularity: An integer value that signals how many different units to
* display in the string. Defaults to 2.
* - langcode: The language code for the language used to format the date.
* Defaults to NULL, which results in the user interface language for the
* page being used.
* - strict: A Boolean value indicating whether or not the timestamp can be
* before the current request time. If TRUE (default) and $timestamp is
* before the current request time, the result string will be "0 seconds".
* If FALSE and $timestamp is before the current request time, the result
* string will be the formatted time difference.
*
* @return string
* A translated string representation of the difference between the given
* timestamp and the current request time. This interval is always positive.
*
* @see \Drupal\Core\Datetime\DateFormatterInterface::formatDiff()
* @see \Drupal\Core\Datetime\DateFormatterInterface::formatTimeDiffSince()
*/
public function formatTimeDiffUntil($timestamp, $options = array());
/**
* Formats the time difference from a timestamp to the current request time.
*
* @param $timestamp
* A UNIX timestamp to compare against the current request time.
* @param array $options
* (optional) An associative array with additional options. The following
* keys can be used:
* - granularity: An integer value that signals how many different units to
* display in the string. Defaults to 2.
* - langcode: The language code for the language used to format the date.
* Defaults to NULL, which results in the user interface language for the
* page being used.
* - strict: A Boolean value indicating whether or not the timestamp can be
* after the current request time. If TRUE (default) and $timestamp is
* after the current request time, the result string will be "0 seconds".
* If FALSE and $timestamp is after the current request time, the result
* string will be the formatted time difference.
*
* @return string
* A translated string representation of the difference between the given
* timestamp and the current request time. This interval is always positive.
*
* @see \Drupal\Core\Datetime\DateFormatterInterface::formatDiff()
* @see \Drupal\Core\Datetime\DateFormatterInterface::formatTimeDiffUntil()
*/
public function formatTimeDiffSince($timestamp, $options = array());
/**
* Formats a time interval between two timestamps.
*
* @param int $from
* A UNIX timestamp, defining the from date and time.
* @param int $to
* A UNIX timestamp, defining the to date and time.
* @param array $options
* (optional) An associative array with additional options. The following
* keys can be used:
* - granularity: An integer value that signals how many different units to
* display in the string. Defaults to 2.
* - langcode: The language code for the language used to format the date.
* Defaults to NULL, which results in the user interface language for the
* page being used.
* - strict: A Boolean value indicating whether or not the $from timestamp
* can be after the $to timestamp. If TRUE (default) and $from is after
* $to, the result string will be "0 seconds". If FALSE and $from is
* after $to, the result string will be the formatted time difference.
*
* @return string
* A translated string representation of the interval. This interval is
* always positive.
*
* @see \Drupal\Core\Datetime\DateFormatterInterface::formatInterval()
* @see \Drupal\Core\Datetime\DateFormatterInterface::formatTimeDiffSince()
* @see \Drupal\Core\Datetime\DateFormatterInterface::formatTimeDiffUntil()
*/
public function formatDiff($from, $to, $options = array());
}

View file

@ -90,7 +90,8 @@ class DrupalDateTime extends DateTimePlus {
* the result of the format() method. Defaults to NULL.
*
* @return string
* The formatted value of the date.
* The formatted value of the date. Since the format may contain user input,
* this value should be escaped when output.
*/
public function format($format, $settings = array()) {
$langcode = !empty($settings['langcode']) ? $settings['langcode'] : $this->langcode;

View file

@ -241,7 +241,7 @@ class Datetime extends DateElementBase {
// placeholders are invalid for HTML5 date and datetime, so an example
// format is appended to the title to appear in tooltips.
$extra_attributes = array(
'title' => t('Date (e.g. !format)', array('!format' => static::formatExample($date_format))),
'title' => t('Date (e.g. @format)', array('@format' => static::formatExample($date_format))),
'type' => $element['#date_date_element'],
);
@ -288,7 +288,7 @@ class Datetime extends DateElementBase {
// Adds the HTML5 attributes.
$extra_attributes = array(
'title' => t('Time (e.g. !format)', array('!format' => static::formatExample($time_format))),
'title' => t('Time (e.g. @format)', array('@format' => static::formatExample($time_format))),
'type' => $element['#date_time_element'],
'step' => $element['#date_increment'],
);