' . t('About') . ''; $output .= '

' . t('The Datetime Range module provides a Date field that stores start dates and times, as well as end dates and times. See the Field module help and the Field UI module help pages for general information on fields and how to create and manage them. For more information, see the online documentation for the Datetime Range module.', [':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_range']) . '

'; $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Managing and displaying date fields') . '
'; $output .= '
' . t('The settings and the display of the Date field can be configured separately. See the Field UI help 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']) : '#']) . '
'; $output .= '
' . t('Displaying dates') . '
'; $output .= '
' . t('Dates can be displayed using the Plain or the Default formatter. The Plain formatter displays the date in the ISO 8601 format. If you choose the Default formatter, you can choose a format from a predefined list that can be managed on the Date and time formats page.', [':date_format_list' => \Drupal::url('entity.date_format.collection')]) . '
'; $output .= '
'; return $output; } } /** * Implements hook_view_presave(). * * When a view is saved using the old string or standard plugin format for * Datetime Range filters or sorts, they will automatically be updated to * Datetime filters or sorts. Old plugins usage must to be considered * deprecated and must be converted before 9.0.0, when this updating layer will * be removed. * * @deprecated in Drupal 8.5.x and will be removed before 9.0.0. * * @see https://www.drupal.org/node/2857691 */ function datetime_range_view_presave(ViewEntityInterface $view) { $config_factory = \Drupal::configFactory(); $displays = $view->get('display'); $changed = FALSE; foreach ($displays as $display_name => &$display) { // Update datetime_range filters. if (isset($display['display_options']['filters'])) { foreach ($display['display_options']['filters'] as $field_name => &$filter) { if ($filter['plugin_id'] === 'string') { $table_data = Views::viewsData()->get($filter['table']); if (!$table_data) { continue; } // Get field config. $filter_views_data = $table_data[$filter['field']]['filter']; if (!isset($filter_views_data['entity_type']) || !isset($filter_views_data['field_name'])) { continue; } $field_storage_name = 'field.storage.' . $filter_views_data['entity_type'] . '.' . $filter_views_data['field_name']; $field_configuration = $config_factory->get($field_storage_name); if ($field_configuration->get('type') === 'daterange') { // Set entity_type if missing. if (!isset($filter['entity_type'])) { $filter['entity_type'] = $filter_views_data['entity_type']; } // Set datetime plugin_id. $filter['plugin_id'] = 'datetime'; // Create datetime value array. $datetime_value = [ 'min' => '', 'max' => '', 'value' => $filter['value'], 'type' => 'date', ]; // Map string operator/value to numeric equivalent. switch ($filter['operator']) { case '=': case 'empty': case 'not empty': $operator = $filter['operator']; break; case '!=': case 'not': $operator = '!='; break; case 'starts': $operator = 'regular_expression'; $datetime_value['value'] = '^' . preg_quote($datetime_value['value']); break; case 'ends': $operator = 'regular_expression'; $datetime_value['value'] = preg_quote($datetime_value['value']) . '$'; break; default: $operator = 'regular_expression'; // Add .* to prevent blank regexes. if (empty($datetime_value['value'])) { $datetime_value['value'] = '.*'; } else { $datetime_value['value'] = preg_quote($datetime_value['value']); } } // Set value and operator. $filter['value'] = $datetime_value; $filter['operator'] = $operator; $changed = TRUE; @trigger_error('Use of string filters for datetime_range fields is deprecated. Use the datetime filters instead. See https://www.drupal.org/node/2857691', E_USER_DEPRECATED); } } } } // Update datetime_range sort handlers. if (isset($display['display_options']['sorts'])) { foreach ($display['display_options']['sorts'] as $field_name => &$sort) { if ($sort['plugin_id'] === 'standard') { $table_data = Views::viewsData()->get($sort['table']); if (!$table_data) { continue; } // Get field config. $sort_views_data = $table_data[$sort['field']]['sort']; if (!isset($sort_views_data['entity_type']) || !isset($sort_views_data['field_name'])) { continue; } $field_storage_name = 'field.storage.' . $sort_views_data['entity_type'] . '.' . $sort_views_data['field_name']; $field_configuration = $config_factory->get($field_storage_name); if ($field_configuration->get('type') === 'daterange') { // Set entity_type if missing. if (!isset($sort['entity_type'])) { $sort['entity_type'] = $sort_views_data['entity_type']; } // Set datetime plugin_id. $sort['plugin_id'] = 'datetime'; $changed = TRUE; @trigger_error('Use of standard sort handlers for datetime_range fields is deprecated. Use the datetime sort handlers instead. See https://www.drupal.org/node/2857691', E_USER_DEPRECATED); } } } } } if ($changed) { $view->set('display', $displays); } }