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.

Command icon 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

trackleft2 created an issue. See original summary.

trackleft2’s picture

Status: Active » Needs review

trackleft2 changed the visibility of the branch 3556714-improve-deprecation-pattern-2-1-x to hidden.

trackleft2 changed the visibility of the branch 3556714-improve-deprecation-pattern to hidden.

trackleft2 changed the visibility of the branch 3556714-improve-deprecation-pattern to active.

trackleft2 changed the visibility of the branch 3556714-improve-deprecation-pattern-2-1-x to active.

trackleft2 changed the visibility of the branch 3556714-improve-deprecation-pattern to hidden.

  • trackleft2 committed fb24e912 on 2.1.x
    [#3556714] feat: Improve deprecation pattern for DateTimeRangeTrait...
trackleft2’s picture

Status: Needs review » Fixed

Fixed in 2.1.0

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.