Change record status: 
Project: 
Introduced in branch: 
8.6.x
Description: 

Datetime Range module now fully integrates with Views, on par with the Datetime integration.

Existing views making use of Datetime Range fields use the default string plugins, while the new integration will use the datetime ones. Running the database updates will update those views, so they will behave like views over Datetime fields.

Important upgrade information

The update will convert existing datetime_range views string plugins operators/values to datetime ones according with this list:

  • string operator "Is equal to" (=) is converted to datetime operator "Is equal to" (=), value is unchanged
  • string operator "Is not equal to" (!=) is converted to datetime operator "Is not equal to" (!=), value is unchanged
  • string operator "Does not contain" (not) is converted to datetime operator "Is not equal to" (!=), value is unchanged
  • string operator "Starts with" (starts) is converted to datetime operator "Regular expression" (regular_expression), value is prefixed with '^'
  • string operator "Ends with" (ends) is converted to datetime operator "Regular expression" (regular_expression), value is suffixed with '$'
  • string operator "Is empty" (empty) is converted to datetime operator "Is empty" (empty), value is unchanged
  • string operator "Is not empty" (not empty) is converted to datetime operator "Is not empty" (not empty), value is unchanged
  • any other operator (contains, word, allwords, not_starts, not_ends, shorterthan, longerthan, regular_expression) maps to regular_expression, value is unchanged if not empty otherwise *. is used

Site builders should review the affected views to check if the new operators and values reflect original views scopes.

Module developers using datetime_range fields in their modules views should update configuration and/or code accordingly.

User interface changes

Before:
before
After:
before

API changes

datetime_type_field_views_data_helper() is a new API helper to integrate datetime views plugins easily for any datetime-based fields. Modules defining custom datetime-based fields can now integrate with Views and benefit of datetime plugins easily.

Example usage in core/modules/datetime_range/datetime_range.views.inc:

/**
 * Implements hook_field_views_data().
 */
function datetime_range_field_views_data(FieldStorageConfigInterface $field_storage) {
  \Drupal::moduleHandler()->loadInclude('datetime', 'inc', 'datetime.views');

  // Get datetime field data for value and end_value.
  $data = datetime_type_field_views_data_helper($field_storage, [], 'value');
  $data = datetime_type_field_views_data_helper($field_storage, $data, 'end_value');

  return $data;
}
Impacts: 
Site builders, administrators, editors
Module developers