Problem/Motivation

Whenever service arguments are changed, a BC layer is needed to avoid fatal errors like

 ArgumentCountError: Too few arguments to function Drupal\twig_field_value\Twig\Extension\FieldValueExtension::__construct(), 4 passed in /core/lib/Drupal/Component/DependencyInjection/Container.php on line 261 and exactly 5 expected in Drupal\twig_field_value\Twig\Extension\FieldValueExtension->__construct() (line 78 of /modules/contrib/twig_field_value/src/Twig/Extension/FieldValueExtension.php)

See #3471185: 2.0.3 update should rebuild containers for the previous attempts of fixing it.

Steps to reproduce

Update the module

Proposed resolution

Add a BC layer

Remaining tasks

Review a PR

User interface changes

None

API changes

The @twig_field_value.twig.extension service constructor now requires @renderer as its 5th parameter

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

taran2l created an issue. See original summary.

taran2l’s picture

Status: Active » Needs review
taran2l’s picture

Issue summary: View changes
anybody’s picture

Assigned: Unassigned » grevil

Thank you very very much @taran2l for providing the example! LGTM!
@Grevil what would you say?

Any further references in the docs that it should be done this way? (Technically it makes sense to me, but also adds some boilerplate)

@taran2l added a good explanation here:

@anybody hi

Unfortunately, this is not how this thing should be fixed, as update runs after cache rebuild (usually), so I can't get to that.

Core always adds a BC layer when arguments change, this should be done here as well.

https://www.drupal.org/project/twig_field_value/issues/3471185#comment-1...

grevil’s picture

Assigned: grevil » Unassigned
Status: Needs review » Needs work

Wow, that is super annoying for such a simple change! Haven't seen that yet.

One last thing:

\Drupal\twig_field_value\Twig\Extension\FieldValueExtension::__constrcut() now requires a 5th parameter of type \Drupal\Core\Render\RendererInterface

__constrcut() => __construct().

That's crazy though... one more reason to actually not use dependency injection....

grevil’s picture

Status: Needs work » Reviewed & tested by the community

Alright, changed the CR typo myself.

Should be good to go now!

  • grevil committed 69fc4106 on 2.0.x authored by taran2l
    Issue #3478474 Add a BC layer for service argument change
    
grevil’s picture

Status: Reviewed & tested by the community » Fixed

Thank you @taran2l!

Status: Fixed » Closed (fixed)

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