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