Problem/Motivation
Bug preventing the latest stable version working with Drupal 9.
Argument 1 passed to Drupal\daterange_compact\DateRangeCompactFormatter::derivePatterns() must implement interface Drupal\daterange_compact\Entity\DateRangeCompactFormatInterface, null given, called in /var/www/html/web/modules/contrib/daterange_compact/src/DateRangeCompactFormatter.php on line 63 in Drupal\daterange_compact\DateRangeCompactFormatter->derivePatterns() (line 96 of modules/contrib/daterange_compact/src/DateRangeCompactFormatter.php).
Steps to reproduce
drupal/core-recommended:~9.2.7
drupal/daterange_compact:^2.0.0
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork daterange_compact-3248081
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 #2
jwilson3For now, I've had to downgrade to 8.x-1.x branch (which does have Drupal 9 compatibility) to solve the issue, which was only discovered out in the wild on a production site (it slipped through our manual UAT process).
composer require drupal/daterange_compact:^1.x-devComment #3
jwilson3Comment #4
erik.erskine commented@jwilson3, is this happening following a new install of 2.0.0, or an upgrade from 8.x-1.x?
Comment #5
jwilson3After upgrade from 8.x-1.x
Comment #6
jwilson3@erik.erskine: I see the message on the release that 2.0.0 is not backward compatible. Do you have any suggestions for migrating from 8.x-1.x to 2.0.0
Comment #7
anruetherThere are some notes in the other issue.
Comment #8
abelcain commentedDear colleagues,
We had same issue but we always had version 2.0.0. We discovered because no daterange compact entity was created.
When no compact data is defined here: /admin/config/regional/daterange-compact-format
Then a message appears:
TypeError: Drupal\daterange_compact\DateRangeCompactFormatter::derivePatterns(): Argument #1 ($format) must be of type Drupal\daterange_compact\Entity\DateRangeCompactFormatInterface, null given, called in /home/abel-santos-corral/openeuropa/era-era-dev/web/modules/contrib/daterange_compact/src/DateRangeCompactFormatter.php on line 63 in Drupal\daterange_compact\DateRangeCompactFormatter->derivePatterns() (line 96 of modules/contrib/daterange_compact/src/DateRangeCompactFormatter.php).The error can be reproduced eliminating all the configurations there.
So maybe at this point:
$patterns = $this->derivePatterns($format, $start_timestamp, $end_timestamp, $timezone);Of function formatTimestampRange there must be any check to avoid that fatal error to happen and be more robust.
Please reproduce and check if the fatal error can be avoided so the site gets not broken in this case. Even though there's configuration provided by the module, a user can delete the configurations so the problem could appear from time to time. So better to have that controlled somehow.
Thanks in advance.
Comment #9
ryankavalsky commentedIs there a solution for this issue, yet? I seem to have run into it myself with Drupal 9.5.11 and daterange_compact 2.0.1.
Comment #10
ryankavalsky commentedNever mind - I've learned that the compact date formats I had set up must not have transferred when upgrading Drupal from 8 to 9, or perhaps when upgrading this module. After re-creating my default compact format, everything worked again.
Comment #13
vladimirausComment #14
vladimirausComment #15
erik.erskine commentedComment #17
erik.erskine commentedThis error happens when the formatter is passed a non-existent config entity ID, as described in #8.
I looked at how the core date formatter handles this situation. If the format doesn't exist or is invalid, a
fallbackdate format is used. This `fallback` format is included as part of the module's default configuration and locked.So it would make sense for this module to behave the same way. Added to 2.1.0.