Problem/Motivation
In testing Drupal CMS with 11.x-dev, I noticed an error from #3579673: Remove lazy declaration and proxy class for MIME type guessers.
[error] The action plugin easy_email_send can not be initialized. ECA is ignoring this action. The issue with this action: Drupal\easy_email\Service\EmailAttachmentEvaluator::__construct(): Argument #3 ($mimeTypeGuesser) must be of type Drupal\Core\ProxyClass\File\MimeType\MimeTypeGuesser, Drupal\Core\File\MimeType\MimeTypeGuesser given, called in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 262
The MimeTypeGuesser Drupal\Core\ProxyClass\File\MimeType\MimeTypeGuesser is deleted. This needs to be updated to Drupal\Core\File\MimeType\MimeTypeGuesser.
This is used in EmailAttachmentEvaluator.
Steps to reproduce
- Install Drupal CMS with core 11.x-dev
- Try to clear the cache
- See the error
Proposed resolution
Update Drupal\Core\ProxyClass\File\MimeType\MimeTypeGuesser to Drupal\Core\File\MimeType\MimeTypeGuesser in EmailAttachmentEvaluator.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 3588366-change-mimetypeguesser-to-7.patch | 2.17 KB | jrochate |
Issue fork easy_email-3588366
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
Comment #3
pameeela commentedComment #4
zengenuity commented#3579673: Remove lazy declaration and proxy class for MIME type guessers didn't apply to D10, but it looks like the same class exists there. So, I think this should work on both. Merged.
Comment #6
jrochate commentedActually it still has problems when using Drupal 11.
[error] The action plugin easy_email_send can not be initialized. ECA is ignoring this action. The issue with this action: Drupal\easy_email\Service\EmailAttachmentEvaluator::__construct(): Argument #3 ($mimeTypeGuesser) must be of type Drupal\Core\File\MimeType\MimeTypeGuesser, Drupal\Core\ProxyClass\File\MimeType\MimeTypeGuesser given, called in /var/www/clients/client2/web2/web/repos/rra/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259Comment #7
jrochate commentedHere is a patch to apply to a 3.0.x-dev that has the MR!59 already merged on the -dev.
Comment #8
jrochate commentedThe `file.mime_type.guesser` service is declared lazy in core's `core.services.yml`, so the container injects `Drupal\Core\ProxyClass\File\MimeType\MimeTypeGuesser` rather than the concrete `Drupal\Core\File\MimeType\MimeTypeGuesser`. The proxy implements `\Symfony\Component\Mime\MimeTypeGuesserInterface` but does **not** extend the concrete class, so the PHP type check in `EmailAttachmentEvaluator::__construct()` fails at instantiation.
This is the same family of regressions that previously affected `smtp`, `mimemail`, `htmlmail`, `s3fs`, and others. The change record at https://www.drupal.org/node/3126004 specifies that modules should type against `\Symfony\Component\Mime\MimeTypeGuesserInterface`, not the concrete Drupal class, precisely because the service is proxied.
In `src/Service/EmailAttachmentEvaluator.php`, change the type hint on the constructor's `$mimeTypeGuesser` parameter (and the matching property `@var` and constructor `@param` docblocks, plus the `use` statement) from `\Drupal\Core\File\MimeType\MimeTypeGuesser` to `\Symfony\Component\Mime\MimeTypeGuesserInterface`.
This is binary-compatible: the proxy implements the interface, the concrete `Drupal\Core\File\MimeType\MimeTypeGuesser` also implements it, and the only method invoked on the property in the file — `guessMimeType($path)` on line 140 — is defined on the interface.
Comment #10
zengenuity commentedCommitted to 3.0.x. Thanks!