Problem/Motivation

Enabling redirect_404 (or any module that decorates logger.factory) causes pages that render an Ad block to fatally error.
The constructor of \Drupal\ad\Track\TrackerFactory is hard‑typehinted to the concrete LoggerChannelFactory class, so dependency injection fails when the decorated service is not that concrete class.

Drupal best practice is to typehint the interface LoggerChannelFactoryInterface so decorated services are accepted.

Steps to reproduce

  1. Install and enable the Ad module (and Ad Content submodule if needed) and place an Ad block so \Drupal\ad\Plugin\Block\AdSlot::build() is invoked.
  2. Install and enable redirect_404 (or another module that decorates logger.factory).
  3. Clear caches and load a page containing the Ad block.

Actual result

TypeError: Drupal\ad\Track\TrackerFactory::__construct(): Argument #2 ($loggerFactory) must be of type Drupal\Core\Logger\LoggerChannelFactory, Drupal\redirect_404\Render\Redirect404LogSuppressor given
in Drupal\ad\Track\TrackerFactory->__construct() (modules/contrib/ad/src/Track/TrackerFactory.php:34)

Expected result

Pages render without fatal errors; the logger factory can be a decorated implementation.

Proposed resolution

Update TrackerFactory to typehint LoggerChannelFactoryInterface in the constructor (and docblock). No service IDs or definitions need to change. This aligns with Drupal DI guidelines and allows decorated services to be injected.

Alternative (also acceptable): inject @logger.channel.ad_content (a Psr\Log\LoggerInterface) directly and avoid calling get() on the factory.

Workaround

Apply a local patch that changes the constructor typehint to the interface, or temporarily disable modules that decorate logger.factory (not ideal).

Remaining tasks

  • Commit the typehint change.
  • (Optional) Add a kernel test that supplies a decorated stub of LoggerChannelFactoryInterface and ensures TrackerFactory constructs.
  • Audit the Ad project for any other constructors that typehint LoggerChannelFactory instead of the interface.
  • MR note: I will open a Merge Request, but at the moment GitLab is not letting me fork the project due to a CORS error. I’ll submit the MR as soon as that is resolved and will attach the patch in the meantime.

User interface changes

None.

API changes

None. Internal constructor type uses the interface; no public API change.

Data model changes

None.

CommentFileSizeAuthor
1.diff1.19 KBdobe

Issue fork ad-3543989

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

dobe created an issue. See original summary.

anybody’s picture

Assigned: Unassigned » lrwebks
Status: Active » Reviewed & tested by the community

@dobe please use MRs instead of patches. Your patch is correct, thank you for the fix! :)

anybody’s picture

lrwebks made their first commit to this issue’s fork.

  • lrwebks committed 6972601a on 11.x
    Issue #3543989 by dobe, anybody: Redirect 404 fatal error
    
lrwebks’s picture

Status: Reviewed & tested by the community » Fixed
dobe’s picture

@anybody as stated in the MR note. I cannot submit MR's because I cannot fork the repo in gitlab. When I try I get a CORS error. So when Drupal.org fixes that. I will definitely! Thank you!

Status: Fixed » Closed (fixed)

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