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.

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

alemadlei created an issue. See original summary.

alemadlei’s picture

Assigned: alemadlei » Unassigned
Status: Active » Needs review

I'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.

alemadlei’s picture

Attach patch from MR

alemadlei’s picture

Corrected name

alemadlei’s picture

plopesc’s picture

Status: Needs review » Needs work

Patch 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.

alemadlei’s picture

So 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.

plopesc’s picture

I 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.

plopesc’s picture

Status: Needs work » Needs review

Since 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 :)

  • plopesc committed 43ad2a03 on 3.0.x
    Issue #3522736: You have requested a non-existent service "...
plopesc’s picture

Status: Needs review » Fixed

MR merged.

Status: Fixed » Closed (fixed)

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