Problem/Motivation

Core prevents service decoration of entity type manager, which is sometimes necessary to override some functions.

Particularly, clean override of handlers.

Right now service decorators need to extend \Drupal\Core\Entity\EntityTypeManager in order to get around this.

Steps to reproduce

Implement a service decorator to entity type manager.
Enable views.
Clear caches.

Proposed resolution

Change dependency injection to interface.

Whether you agree decorating this service is good or not, it should still be possible. And typehinting concrete implementations is seen as a big no-no.

Remaining tasks

\Drupal\views\FieldViewsDataProvider::__construct(EntityTypeManager entityTypeManager)

to

\Drupal\views\FieldViewsDataProvider::__construct(EntityTypeManagerInterface entityTypeManager)

There is also a \Drupal\Tests\workspaces\Kernel\EntityReferenceSupportedNewEntitiesConstraintValidatorTest::$entityTypeManager, but that is not runtime code. So that can be optional/bonus change.

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

None

Issue fork drupal-3564264

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

dpi created an issue. See original summary.

jani made their first commit to this issue’s fork.

jani’s picture

I've created a merge request that changes the constructor typehint from EntityTypeManager to EntityTypeManagerInterface in \Drupal\views\FieldViewsDataProvider.

The changes include:
1. Updated the use statement on line 7 to import EntityTypeManagerInterface instead of EntityTypeManager
2. Changed the constructor parameter typehint on line 23 from EntityTypeManager to EntityTypeManagerInterface

This allows for proper service decoration of the entity type manager as described in the issue.

longwave made their first commit to this issue’s fork.

longwave’s picture

Status: Active » Needs review
rollins’s picture

Status: Needs review » Reviewed & tested by the community

I strongly support this change. Relying on the concrete EntityTypeManager class in the constructor creates unnecessary tight coupling.
Switching to EntityTypeManagerInterface is the architecturally correct approach here.

RTBC.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to main and cherry-picked to 11.x, thanks!

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.

  • catch committed 201f1ec9 on 11.x
    task: #3564264 Fix concrete typehinting of EntityTypeManager
    
    By: dpi
    By...

  • catch committed 35a84e6d on main
    task: #3564264 Fix concrete typehinting of EntityTypeManager
    
    By: dpi
    By...

  • catch committed 0d0e2802 on 11.3.x
    task: #3564264 Fix concrete typehinting of EntityTypeManager
    
    By: dpi
    By...
catch’s picture

Backported to 11.3.x via a request from @amateescu since this would unblock some changes in Trash module. We're not really changing what the constructor takes here except opening it up.

dpi’s picture

Thanks @catch, that'll help tidy up some things for some private projects that triggered the related change in #3564263: Change entity type manager class override to service decoration and also https://git.drupalcode.org/project/pinto_entity/-/blob/1.x/src/PintoEnti... without needing to wait for new core minor <3

quietone’s picture

Version: 11.x-dev » 11.3.x-dev

Changing version because it was backported.

Status: Fixed » Closed (fixed)

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