Problem/Motivation
The deprecation notice for the DateTimeRangeTrait dependency is currently triggered in the constructor of ApStyleDateRangeFieldFormatter. This means a deprecation warning is emitted on every instantiation of the formatter, even when no deprecated trait functionality is being used. This is inconsistent with Drupal core deprecation patterns, where warnings should only be triggered when deprecated behavior is executed.
Additionally, the DateTimeRangeTrait was removed in a later commit on the 2.1.x branch as part of an unrelated change. This means there is currently no stable deprecation path for contributed or custom formatters that may extend ApStyleDateRangeFieldFormatter and rely on the trait APIs.
Steps to reproduce
- Enable date_ap_style:2.1.0-rc1 or current 2.1.x-dev.
- View any entity that uses ApStyleDateRangeFieldFormatter.
- A deprecation warning is triggered even when DateTimeRangeTrait functionality is not invoked.
Proposed resolution
Re-add the DateTimeRangeTrait to ApStyleDateRangeFieldFormatter for 2.1.x and wrap all trait methods with deprecation-triggering wrapper methods. This ensures:
- A stable, backwards-compatible deprecation path for any downstream code that relies on the trait methods.
- Deprecation warnings only trigger when deprecated functionality is actually used.
The constructor-level deprecation trigger should be removed.
Remaining tasks
- Re-add DateTimeRangeTrait to ApStyleDateRangeFieldFormatter.
- Add wrapper methods for all trait methods, emitting @trigger_error only when called.
- Remove constructor-level @trigger_error().
- Document that the trait will be removed in 3.0.0.
- Code review and automated test verification.
User interface changes
None.
API changes
None immediately. The DateTimeRangeTrait methods remain available but are now explicitly deprecated and will be removed in 3.0.0.
Data model changes
None.
Issue fork date_ap_style-3556714
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
trackleft2Comment #10
trackleft2Fixed in 2.1.0