Problem/Motivation
We are using the
https://www.drupal.org/project/symfony_mailer_queue →
module, to send mails using a queue.
Queued emails sent using the LegacyEmailBuilder
fail to be sent, and fail with the error:
Unknown named parameter $__disable_customize__ in symfony_mailer/src/EmailFactory.php on line 92
.
Also see
🐛
Remove '__disable_customize__' parameters while queuing legacy emails
Active
for more information about this.
In short, the LegacyEmailBuilder
is adding a __disable_customize__
parameter that it is not using as a method argument for createParams()
.
public function createParams(EmailInterface $email, ?array $legacy_message = NULL) {
assert($legacy_message != NULL);
$email->setParam('legacy_message', $legacy_message)
->setParam('__disable_customize__', TRUE);
}
This causes the EmailFactory
to break when doing this:
$builder->createParams($email, ...$params);
Steps to reproduce
For now it is easy to replicate when using the
https://www.drupal.org/project/symfony_mailer_queue →
module and configure the legacy emails to be sent via a queue.
Proposed resolution
Validate the parameters before calling $builder->createParams($email, ...$params);
, and remove invalid params. Something like this:
$reflection = new \ReflectionMethod($builder, 'createParams');
$valid_params = array_intersect_key($params, array_flip(array_map(
static fn($param) => $param->getName(),
// Skip the first parameter, which is the email object itself.
array_slice($reflection->getParameters(), 1)
)));
$builder->createParams($email, ...$valid_params);
This should prevent any errors caused by builders that use params that are not an argument of createParams()
.
Remaining tasks
- Discuss the best solution.
- Write a patch
- Review
- Commit
User interface changes
None
API changes
None
Data model changes
None