Score:0

AliasManagerInterface -deprecated Drupal\Core\Path\AliasManagerInterface

us flag

Error:

The website encountered an unexpected error. Please try again later. TypeError: Argument passed to Drupal{module name}\Theme{class name}::__construct() must implement interface Drupal\path_alias\AliasManagerInterface, instance of Drupal\Core\Path\AliasManager

Getting error in the construct method, please suggest a solution to rectify the error.

Try to modify the "AliasManagerInterface" as "use Drupal\Core\Path\AliasManagerInterface" deprecated and we are now using "use Drupal\path_alias\AliasManagerInterface" but actually getting error inside construct method as mentioned below.

code:

 use Drupal\path_alias\AliasManagerInterface;



  /**
   * Protected pathAlias variable.
   *
   * @var Drupal\path_alias\AliasManagerInterface
   */
  protected $pathAlias;


  public function __construct(AliasManagerInterface $pathAlias) {
    
    $this->pathAlias = $pathAlias;

  }
Score:4
de flag

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

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.