Problem/Motivation
When saving the configuration form of the Advanced 403 Redirect module, a
TypeError is thrown due to an incorrect type hint in the constructor of
`SourceValidationConstraintValidator`.
The constructor declares `Drupal\Core\Routing\RouterInterface` as the type
for argument #3 (`$router`), but the Drupal service container injects
`Drupal\Core\Routing\Router` (a concrete class), which does not satisfy the
`RouterInterface` type hint in all Drupal/environment setups.
**Full error:**
TypeError: Drupal\advanced_403_redirect\Plugin\Validation\Constraint\SourceValidationConstraintValidator::__construct():
Argument #3 ($router) must be of type Drupal\Core\Routing\RouterInterface,
Drupal\Core\Routing\Router given, called in
/var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php
on line 261 in
Drupal\advanced_403_redirect\Plugin\Validation\Constraint\SourceValidationConstraintValidator->__construct()
(line 59 of modules/contrib/advanced_403_redirect/src/Plugin/Validation/Constraint/SourceValidationConstraintValidator.php).
Steps to reproduce
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork advanced_403_redirect-3592673
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
Comment #3
dkmishra commentedFor me, it is throwing the following error:
InvalidArgumentException: Class "advanced_403_redirect.source_validator" does not exist. in Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (line 32 of /var/www/html/interview/web/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php).
Comment #5
dkmishra commentedWhile reviewing, I found that the configuration form still throws the following error:
InvalidArgumentException: Class "advanced_403_redirect.source_validator" does not exist. in Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (line 32 of /var/www/html/interview/web/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php).The issue occurs because Drupal is trying to load a service named
advanced_403_redirect.source_validator, but it cannot find the corresponding service definition inadvanced_403_redirect.services.yml.In the SourceValidationConstraint.php file, the validatedBy() method may be returning:
return 'advanced_403_redirect.source_validator';Comment #7
harpreet_singh_saluja commented