Problem/Motivation
When managing display setttings on a node with recurring events, changing the configuration of other fields might cause this problem:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "daterange_compact.date_range.formatter". Did you mean this: "daterange_compact.formatter"? in Drupal\Component\DependencyInjection\Container->get() (line 157 of /var/www/html/docroot/core/lib/Drupal/Component/DependencyInjection/Container.php).
This is because /recurring_events/src/Plugin/Field/FieldFormatter/EventInstanceDateCompactFormatter.php
does this on line 90
$container->get('daterange_compact.date_range.formatter'),
And according to the formatter module https://www.drupal.org/project/daterange_compact/releases/2.0.0 the service name got changed.
Steps to reproduce
- Add an entity type with multiple fields, one being dates that are recurring as the last.
- Try to update display settings of other fields.
- The UI might report the error.
Proposed resolution
Update the service name being requested.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3522736-date-range-formatter-service-fix.patch | 3.51 KB | alemadlei |
Issue fork recurring_events-3522736
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
alemadleiI've submitted a first MR.
I discovered that this happens when I use alongside the field_limiter module.
But this also seems related to custom formats from date range compact. So if a display setting is using that it will fail. But these updates should take care of linking the classes properly.
Comment #4
alemadleiAttach patch from MR
Comment #5
alemadleiCorrected name
Comment #6
alemadleiComment #7
plopescPatch looks good, but I would prefer not to add a new dependency for all the module installations.
It might be declared as a soft dependency where the formatter is only available if the service is available as well.
Comment #8
alemadleiSo how would you recommend me address this with the patch?
If I remove the composer dependency how should the formatter class be managed? Since it is a plugin it would be automatically loaded.
Comment #9
plopescI would declare the service as an optional parameter in the formatter constructor.
Then in create() method, use the NULL_ON_INVALID_REFERENCE class constant to use NULL instead of throwing an exception if the service is missing.
Finally, the isApplicable() method will define the formatter as available if the module is installed.
Another option, probably simpler would be to define the daterange_compact module as formatter provider. Hence will be discoverable if only the provider is installed.
Comment #11
plopescSince many of the issues related to #3480491: Roadmap to modernize code for D11 + PHP 8.3 modified this file last days, this issue ended up in a single line MR :)
Comment #13
plopescMR merged.