Remove usage of Drupal\datetime_range\DateTimeRangeTrait.

Created on 28 August 2025, 13 days ago

Problem/Motivation

The Date AP Style module currently includes DateTimeRangeTrait in the ApStyleDateRangeFieldFormatter and has dependencies on the datetime and datetime_range modules. These dependencies may not be necessary for all use cases:

  • The trait adds functionality that may not be essential for the core AP Style formatting
  • The module dependencies force users to enable datetime modules even if they only want to format timestamp-based fields (created, changed, published_at)
  • This creates unnecessary coupling to contrib/core modules

Steps to reproduce

  1. Install the Date AP Style module
  2. Note that datetime and datetime_range modules are automatically enabled as dependencies
  3. Observe that ApStyleDateRangeFieldFormatter uses DateTimeRangeTrait

Proposed resolution

  1. Remove the use DateTimeRangeTrait; from ApStyleDateRangeFieldFormatter
  2. Remove the use Drupal\datetime_range\DateTimeRangeTrait; import
  3. Remove drupal:datetime and drupal:datetime_range from date_ap_style.info.yml dependencies
  4. Remove datetime and daterange field types from formatter annotations if not needed
  5. Ensure all existing functionality continues to work for timestamp-based fields

Backwards compatibility considerations

Breaking change: Removing DateTimeRangeTrait could break existing code that extends ApStyleDateRangeFieldFormatter and relies on trait methods like buildDateRangeValue() or formatDateRange().

Recommended approach:

  • Consider deprecating the trait in a minor release (1.x) with deprecation notices
  • Remove the trait only in a major version bump (2.0)
  • Document the BC break in CHANGELOG.md
  • Evaluate if the trait provides essential functionality that justifies keeping the dependencies

Remaining tasks

  • Remove trait usage from formatter
  • Update dependencies in info.yml
  • Update field type annotations
  • Test that formatters still work for timestamp fields
  • Update documentation if needed

User interface changes

None - formatters will continue to work for supported field types.

API changes

  • Remove dependency on DateTimeRangeTrait
  • Reduce module dependencies

Data model changes

None - existing configurations will continue to work.

πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States trackleft2 Tucson, AZ πŸ‡ΊπŸ‡Έ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024