datetime.module 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @file
  4. * Field hooks to implement a simple datetime field.
  5. */
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. /**
  8. * Defines the timezone that dates should be stored in.
  9. *
  10. * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use
  11. * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::STORAGE_TIMEZONE
  12. * instead.
  13. *
  14. * @see https://www.drupal.org/node/2912980
  15. */
  16. const DATETIME_STORAGE_TIMEZONE = 'UTC';
  17. /**
  18. * Defines the format that date and time should be stored in.
  19. *
  20. * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use
  21. * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATETIME_STORAGE_FORMAT
  22. * instead.
  23. *
  24. * @see https://www.drupal.org/node/2912980
  25. */
  26. const DATETIME_DATETIME_STORAGE_FORMAT = 'Y-m-d\TH:i:s';
  27. /**
  28. * Defines the format that dates should be stored in.
  29. *
  30. * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.x. Use
  31. * \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATE_STORAGE_FORMAT
  32. * instead.
  33. *
  34. * @see https://www.drupal.org/node/2912980
  35. */
  36. const DATETIME_DATE_STORAGE_FORMAT = 'Y-m-d';
  37. /**
  38. * Implements hook_help().
  39. */
  40. function datetime_help($route_name, RouteMatchInterface $route_match) {
  41. switch ($route_name) {
  42. case 'help.page.datetime':
  43. $output = '';
  44. $output .= '<h3>' . t('About') . '</h3>';
  45. $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' => \Drupal::url('help.page', ['name' => 'field']), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#', ':datetime_do' => 'https://www.drupal.org/documentation/modules/datetime']) . '</p>';
  46. $output .= '<h3>' . t('Uses') . '</h3>';
  47. $output .= '<dl>';
  48. $output .= '<dt>' . t('Managing and displaying date fields') . '</dt>';
  49. $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')) ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#']) . '</dd>';
  50. $output .= '<dt>' . t('Displaying dates') . '</dt>';
  51. $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' => \Drupal::url('entity.date_format.collection')]) . '</dd>';
  52. $output .= '</dl>';
  53. return $output;
  54. }
  55. }
  56. /**
  57. * Sets a consistent time on a date without time.
  58. *
  59. * The default time for a date without time can be anything, so long as it is
  60. * consistently applied. If we use noon, dates in most timezones will have the
  61. * same value for in both the local timezone and UTC.
  62. *
  63. * @param $date
  64. *
  65. * @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use
  66. * \Drupal\Component\Datetime\DateTimePlus::setDefaultDateTime() or
  67. * \Drupal\Core\Datetime\DrupalDateTime::setDefaultDateTime() instead.
  68. *
  69. * @see https://www.drupal.org/node/2880931
  70. */
  71. function datetime_date_default_time($date) {
  72. @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);
  73. // For maximum BC before this method is removed, we do not use the
  74. // recommendation from the deprecation method. Instead, we call the setTime()
  75. // method directly. This allows the method to continue to work with
  76. // \DateTime, DateTimePlus, and DrupalDateTime objects (and classes that
  77. // may derive from them).
  78. $date->setTime(12, 0, 0);
  79. }