You must be on Drupal 8.8, or Drupal 8.9.
Drupal8, until 8.7, declared the path.alias_manager
service, that referred to Drupal\Core\Path\AliasManager
. In Drupal 8.8, that service was deprecated, to be removed in Drupal 9.x. A new service was introduced as a replacement, the path_alias.manager
service, which refers to Drupal\path_alias\AliasManager
.
The dependency injection from the original question is expecting an object of implementing the interface Drupal\path_alias\AliasManagerInterface
, and the path_alias.manager
service does implement this interface. However, the error says that the dependency injection is not receiving an object that implements Drupal\path_alias\AliasManagerInterface
, it is incorrectly receiving an object of type Drupal\Core\Path\AliasManager
, giving you the error.
The original question does not show how the dependency is being generated, but in Drupal the two most common methods are creating a service and declaring dependencies in the *.services.yml
file for the module, or in the create()
method of the class. Whichever method was used, is still using the old path.alias_manager
service, and therefore passing Drupal\Core\Path\AliasManager
to the class instead of Drupal\path_alias\AliasManager
. The solution is to change service being injected from path.alias_manager
to path_alias.manager
.
Further reading: https://www.drupal.org/node/3092086