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
- Install Drupal core 11.4.2.
- Enable the core Path Alias module.
- Install and enable Visitors 8.x-2.32.
- Load a page where
visitors_page_attachments()runs. - The page returns a 500 error because
visitors.visibilitycannot 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
PathMatcherInterfaceimplementation. - 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.
| Comment | File | Size | Author |
|---|---|---|---|
| visitors-path-matcher-interface-compatibility.patch | 3.51 KB | david-urban |
Comments
Comment #2
bluegeek9 commentedHello David,
This issue was reported and resolved under #3609339: VisibilityService::__construct(): Argument #4 ($path_matcher)
Comment #3
david-urban commentedOh, sorry, I searched, but did not think to look through resolved issues. Looking forward to new release including this fix.
Comment #4
bluegeek9 commentedNo worries. I hope to have a release later this week. There are a couple other bugs I hope to also fix this week.
Comment #5
bluegeek9 commented