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

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

drupgmi created an issue. See original summary.

drupgmi changed the visibility of the branch 3592673-typeerror-sourcevalidationconstraintvalidator-uses to hidden.

dkmishra’s picture

For 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).

dkmishra’s picture

While 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 in advanced_403_redirect.services.yml.

In the SourceValidationConstraint.php file, the validatedBy() method may be returning: return 'advanced_403_redirect.source_validator';

harpreet_singh_saluja’s picture

Assigned: drupgmi » Unassigned
Status: Active » Fixed

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.

Status: Fixed » Closed (fixed)

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