Provide service aliases for autowiring

Created on 28 August 2025, about 8 hours ago

Problem/Motivation

Drupal has been expanding its support of services that can have their arguments autowired. One exciting new example of this is the ability to use object-oriented hooks in Drupal 11.

When adding the externalauth.authmap service to an autowired hook class, I ran into this error:
Cannot autowire service "Drupal\custom_module\Hook\MyCustomHooks": argument "$authmap" of method "__construct()" references interface "Drupal\externalauth\AuthmapInterface" but no such service exists. You should maybe alias this interface to the existing "externalauth.authmap" service.

Steps to reproduce

  1. Create a class with a hook following the documentation here β†’ .
  2. Add a services.yml file for your hook class and include autowire: true
  3. Make sure to include a construct method for your class as shown below and observe the error message:
<?php

namespace Drupal\custom_module\Hook;

use Drupal\externalauth\AuthmapInterface;

class MyCustomHooks {

  public function __construct(
    private AuthmapInterface $authmap,
  ) {}

...
}

Proposed resolution

Create aliases for externalauth.authmap and externalauth.externalauth in externalauth.services.yml.

πŸ’¬ Support request
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States angelamnr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024