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