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

  1. Install Drupal CMS with core 11.x-dev
  2. Try to clear the cache
  3. See the error

Proposed resolution

Update Drupal\Core\ProxyClass\File\MimeType\MimeTypeGuesser to Drupal\Core\File\MimeType\MimeTypeGuesser in EmailAttachmentEvaluator.

Issue fork easy_email-3588366

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

pameeela created an issue. See original summary.

pameeela’s picture

Status: Active » Needs review
zengenuity’s picture

Status: Needs review » Fixed

#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.

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.

jrochate’s picture

Status: Fixed » Needs work

Actually 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 259

jrochate’s picture

Status: Needs work » Needs review
StatusFileSize
new2.17 KB

Here is a patch to apply to a 3.0.x-dev that has the MR!59 already merged on the -dev.

jrochate’s picture

The `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.

  • zengenuity committed b1df995e on 3.0.x
    fix: #3588366 Change MimeTypeGuesser to core/lib/Drupal/Core/File/...
zengenuity’s picture

Status: Needs review » Fixed

Committed to 3.0.x. Thanks!

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.

Status: Fixed » Closed (fixed)

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