datetime.module 4.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @file
  4. * Field hooks to implement a simple datetime field.
  5. */
  6. use Drupal\Core\Url;
  7. use Drupal\Core\Routing\RouteMatchInterface;
  8. /**
  9. * Defines the timezone that dates should be stored in.
  10. *
  11. * @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use
  12. * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::STORAGE_TIMEZONE
  13. * instead.
  14. *
  15. * @see https://www.drupal.org/node/2912980
  16. */
  17. const DATETIME_STORAGE_TIMEZONE = 'UTC';
  18. /**
  19. * Defines the format that date and time should be stored in.
  20. *
  21. * @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use
  22. * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATETIME_STORAGE_FORMAT
  23. * instead.
  24. *
  25. * @see https://www.drupal.org/node/2912980
  26. */
  27. const DATETIME_DATETIME_STORAGE_FORMAT = 'Y-m-d\TH:i:s';
  28. /**
  29. * Defines the format that dates should be stored in.
  30. *
  31. * @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use
  32. * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATE_STORAGE_FORMAT
  33. * instead.
  34. *
  35. * @see https://www.drupal.org/node/2912980
  36. */
  37. const DATETIME_DATE_STORAGE_FORMAT = 'Y-m-d';
  38. /**
  39. * Implements hook_help().
  40. */
  41. function datetime_help($route_name, RouteMatchInterface $route_match) {
  42. switch ($route_name) {
  43. case 'help.page.datetime':
  44. $output = '';
  45. $output .= '<h3>' . t('About') . '</h3>';
  46. $output .= '<p>' . t('The Datetime module provides a Date field that stores dates and times. It also provides the Form API elements <em>datetime</em> and <em>datelist</em> for use in programming modules. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI module help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":datetime_do">online documentation for the Datetime module</a>.', [':field' => Url::fromRoute('help.page', ['name' => 'field'])->toString(), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#', ':datetime_do' => 'https://www.drupal.org/documentation/modules/datetime']) . '</p>';
  47. $output .= '<h3>' . t('Uses') . '</h3>';
  48. $output .= '<dl>';
  49. $output .= '<dt>' . t('Managing and displaying date fields') . '</dt>';
  50. $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the Date field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#']) . '</dd>';
  51. $output .= '<dt>' . t('Displaying dates') . '</dt>';
  52. $output .= '<dd>' . t('Dates can be displayed using the <em>Plain</em> or the <em>Default</em> formatter. The <em>Plain</em> formatter displays the date in the <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> format. If you choose the <em>Default</em> formatter, you can choose a format from a predefined list that can be managed on the <a href=":date_format_list">Date and time formats</a> page.', [':date_format_list' => Url::fromRoute('entity.date_format.collection')->toString()]) . '</dd>';
  53. $output .= '</dl>';
  54. return $output;
  55. }
  56. }
  57. /**
  58. * Sets a consistent time on a date without time.
  59. *
  60. * The default time for a date without time can be anything, so long as it is
  61. * consistently applied. If we use noon, dates in most timezones will have the
  62. * same value for in both the local timezone and UTC.
  63. *
  64. * @param $date
  65. *
  66. * @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use
  67. * \Drupal\Component\Datetime\DateTimePlus::setDefaultDateTime() or
  68. * \Drupal\Core\Datetime\DrupalDateTime::setDefaultDateTime() instead.
  69. *
  70. * @see https://www.drupal.org/node/2880931
  71. */
  72. function datetime_date_default_time($date) {
  73. @trigger_error('datetime_date_default_time() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Component\Datetime\DateTimePlus::setDefaultDateTime() or \Drupal\Core\Datetime\DrupalDateTime::setDefaultDateTime() instead. See https://www.drupal.org/node/2880931.', E_USER_DEPRECATED);
  74. // For maximum BC before this method is removed, we do not use the
  75. // recommendation from the deprecation method. Instead, we call the setTime()
  76. // method directly. This allows the method to continue to work with
  77. // \DateTime, DateTimePlus, and DrupalDateTime objects (and classes that
  78. // may derive from them).
  79. $date->setTime(12, 0, 0);
  80. }