Problem/Motivation

After updating to Drupal core 11.4.2, pages can fail with a 500 error when the Visitors module is enabled.

The failure happens while Drupal is constructing the visitors.visibility service:

TypeError: Drupal\visitors\Service\VisibilityService::__construct():
Argument #4 ($path_matcher) must be of type Drupal\Core\Path\PathMatcher,
Drupal\path_alias\AliasPathMatcher given

Drupal core now decorates the path.matcher service with Drupal\path_alias\AliasPathMatcher. That class correctly implements Drupal\Core\Path\PathMatcherInterface, but it is not an instance of the concrete Drupal\Core\Path\PathMatcher class currently type-hinted by Visitors.

Steps to reproduce

  1. Install Drupal core 11.4.2.
  2. Enable the core Path Alias module.
  3. Install and enable Visitors 8.x-2.32.
  4. Load a page where visitors_page_attachments() runs.
  5. The page returns a 500 error because visitors.visibility cannot be constructed.

Proposed resolution

Update Drupal\visitors\Service\VisibilityService to type-hint Drupal\Core\Path\PathMatcherInterface instead of the concrete Drupal\Core\Path\PathMatcher class.

The service already only depends on path matcher behavior exposed by the interface, so no service definition change is needed. The existing @path.matcher service argument remains correct.

Also update the related unit test mock and PHPDoc annotations to use PathMatcherInterface.

Remaining tasks

  • Add/update test coverage so the constructor accepts a PathMatcherInterface implementation.
  • Review and commit the patch.

User interface changes

None.

API changes

The constructor type hint for VisibilityService changes from PathMatcher to PathMatcherInterface. This is a compatible loosening of the accepted dependency type.

Data model changes

None.

Comments

david-urban created an issue. See original summary.

bluegeek9’s picture

Category: Bug report » Support request
Related issues: +#3609339: VisibilityService::__construct(): Argument #4 ($path_matcher)

Hello David,

This issue was reported and resolved under #3609339: VisibilityService::__construct(): Argument #4 ($path_matcher)

david-urban’s picture

Oh, sorry, I searched, but did not think to look through resolved issues. Looking forward to new release including this fix.

bluegeek9’s picture

No worries. I hope to have a release later this week. There are a couple other bugs I hope to also fix this week.

bluegeek9’s picture

Status: Active » Closed (duplicate)

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.