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
- 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.
- Install and enable redirect_404 (or another module that decorates
logger.factory
).
- 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.