Problem/Motivation

As per the documentation - https://api.drupal.org/api/drupal/core!core.api.php/function/hook_mail_a... - the 'body' key of the $message attribute should be an array of strings. In the InviteByEmail plugin it is a single string.

As a result, @Mail plugins that are being type strict will fail to process invitation emails.

Steps to reproduce

Send an invitation by email with a mail plugin that requires the $message['body'] to be an array (as per the documentation)

Proposed resolution

Make it an array with a single item:

$message['body'][] = \Drupal::service('renderer')->render($body)->__toString();

Instead of:

$message['body'] = \Drupal::service('renderer')->render($body)->__toString();

Issue fork invite-3227581

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

kalpaitch created an issue. See original summary.

kalpaitch’s picture

Status: Active » Needs review
renatog’s picture

Version: 8.x-1.x-dev » 2.0.x-dev

We're planning to release the new version 2.0.x so let's move this for the new version

renatog’s picture

StatusFileSize
new742 bytes

Hey @kalpaitch, thanks for you fix. I've try to apply that on 2.0.x, so follow the new patch

renatog’s picture

Status: Needs review » Needs work

I was trying but is returning this error:

Error: [] operator not supported for strings in Drupal\invite_by_email\Plugin\Invite\InviteByEmail->send() (line 97 of /app/modules/contrib/invite/modules/invite_by_email/src/Plugin/Invite/InviteByEmail.php)
#0 /app/modules/contrib/invite/src/Entity/Invite.php(98): Drupal\invite_by_email\Plugin\Invite\InviteByEmail->send(Object(Drupal\invite\Entity\Invite))
#1 /app/core/lib/Drupal/Core/Entity/EntityStorageBase.php(601): Drupal\invite\Entity\Invite->postSave(Object(Drupal\Core\Entity\Sql\SqlContentEntityStorage), false)
#2 /app/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(778): Drupal\Core\Entity\EntityStorageBase->doPostSave(Object(Drupal\invite\Entity\Invite), false)
#3 /app/core/lib/Drupal/Core/Entity/EntityStorageBase.php(527): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object(Drupal\invite\Entity\Invite), false)
#4 /app/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(802): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\invite\Entity\Invite))
#5 /app/core/lib/Drupal/Core/Entity/EntityBase.php(339): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\invite\Entity\Invite))
#6 /app/modules/contrib/invite/modules/invite_by_email/src/Form/InviteByEmailBlockForm.php(83): Drupal\Core\Entity\EntityBase->save()
#7 [internal function]: Drupal\invite_by_email\Form\InviteByEmailBlockForm->submitForm(Array, Object(Drupal\Core\Form\FormState))
#8 /app/core/lib/Drupal/Core/Form/FormSubmitter.php(114): call_user_func_array(Array, Array)
#9 /app/core/lib/Drupal/Core/Form/FormSubmitter.php(52): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#10 /app/core/lib/Drupal/Core/Form/FormBuilder.php(592): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#11 /app/core/lib/Drupal/Core/Form/FormBuilder.php(320): Drupal\Core\Form\FormBuilder->processForm('invite_by_email...', Array, Object(Drupal\Core\Form\FormState))
#12 /app/core/lib/Drupal/Core/Form/FormBuilder.php(219): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\invite_by_email\Form\InviteByEmailBlockForm), Object(Drupal\Core\Form\FormState))
#13 /app/modules/contrib/invite/modules/invite_by_email/src/Plugin/Block/InviteByEmailBlock.php(55): Drupal\Core\Form\FormBuilder->getForm(Object(Drupal\invite_by_email\Form\InviteByEmailBlockForm), 'invite_type_1')
#14 /app/core/modules/block/src/BlockViewBuilder.php(171): Drupal\invite_by_email\Plugin\Block\InviteByEmailBlock->build()
#15 [internal function]: Drupal\block\BlockViewBuilder::preRender(Array)
#16 /app/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array(Array, Array)
#17 /app/core/lib/Drupal/Core/Render/Renderer.php(772): Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_ren...', 'exception', 'Drupal\\Core\\Ren...')
#18 /app/core/lib/Drupal/Core/Render/Renderer.php(363): Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array)
#19 /app/core/lib/Drupal/Core/Render/Renderer.php(435): Drupal\Core\Render\Renderer->doRender(Array)
#20 /app/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, false)
#21 /app/core/lib/Drupal/Core/Template/TwigExtension.php(463): Drupal\Core\Render\Renderer->render(Array)
#22 /app/sites/default/files/php/twig/6224546f2e02c_page.html.twig_100POH59ZZNUIb6_QmQika3wp/H8D_eEqcG2R82T7hBHFaxRl596tkNMPta1gkIy3LvCc.php(97): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#23 /app/vendor/twig/twig/src/Template.php(405): __TwigTemplate_62d0a43f7cd0bb02376d702c9c81ab246b081d523a2e464861aea8a51224c924->doDisplay(Array, Array)
#24 /app/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#25 /app/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#26 /app/core/themes/engines/twig/twig.engine(55): Twig\Template->render(Array)
#27 /app/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('core/themes/bar...', Array)
#28 /app/core/lib/Drupal/Core/Render/Renderer.php(422): Drupal\Core\Theme\ThemeManager->render('page', Array)
#29 /app/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, false)
#30 /app/core/lib/Drupal/Core/Template/TwigExtension.php(463): Drupal\Core\Render\Renderer->render(Array)
#31 /app/sites/default/files/php/twig/6224546f2e02c_html.html.twig_u_gsYzYZuZjwJlppV6F5rlR3F/dKb2EBGdAOONpHH2fn9O3hR5N5IXmPztYWUbPSO-uQE.php(86): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#32 /app/vendor/twig/twig/src/Template.php(405): __TwigTemplate_4a6ad5967f4f88e0cc1847f3ae888332bcf581ff18f678552c517739b95d3127->doDisplay(Array, Array)
#33 /app/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#34 /app/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
#35 /app/core/themes/engines/twig/twig.engine(55): Twig\Template->render(Array)
#36 /app/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('core/themes/bar...', Array)
#37 /app/core/lib/Drupal/Core/Render/Renderer.php(422): Drupal\Core\Theme\ThemeManager->render('html', Array)
#38 /app/core/lib/Drupal/Core/Render/Renderer.php(201): Drupal\Core\Render\Renderer->doRender(Array, false)
#39 /app/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(162): Drupal\Core\Render\Renderer->render(Array)
#40 /app/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#41 /app/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(163): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#42 /app/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#43 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#44 /app/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#45 /app/vendor/symfony/http-kernel/HttpKernel.php(163): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ViewEvent), 'kernel.view')
#46 /app/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 2)
#47 /app/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 2, true)
#48 /app/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 2, true)
#49 /app/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 2, true)
#50 /app/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 2, true)
#51 /app/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 2, true)
#52 /app/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 2, true)
#53 /app/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 2, true)
#54 /app/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php(166): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 2)
#55 /app/core/lib/Drupal/Core/EventSubscriber/DefaultExceptionHtmlSubscriber.php(122): Drupal\Core\EventSubscriber\DefaultExceptionHtmlSubscriber->makeSubrequest(Object(Symfony\Component\HttpKernel\Event\ExceptionEvent), '/system/404', 404)
#56 /app/core/lib/Drupal/Core/EventSubscriber/HttpExceptionSubscriberBase.php(109): Drupal\Core\EventSubscriber\DefaultExceptionHtmlSubscriber->on404(Object(Symfony\Component\HttpKernel\Event\ExceptionEvent))
#57 [internal function]: Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase->onException(Object(Symfony\Component\HttpKernel\Event\ExceptionEvent), 'kernel.exceptio...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#58 /app/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ExceptionEvent), 'kernel.exceptio...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#59 /app/vendor/symfony/http-kernel/HttpKernel.php(219): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ExceptionEvent), 'kernel.exceptio...')
#60 /app/vendor/symfony/http-kernel/HttpKernel.php(91): Symfony\Component\HttpKernel\HttpKernel->handleThrowable(Object(Symfony\Component\HttpKernel\Exception\NotFoundHttpException), Object(Symfony\Component\HttpFoundation\Request), 1)
#61 /app/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#62 /app/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#63 /app/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#64 /app/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#65 /app/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#66 /app/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#67 /app/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#68 /app/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#69 /app/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#70 {main}

Do you have some idea about what can be?

dale42’s picture

I believe this issue would be resolved by using the code in #3275572: Implement hook_mail().

I can create a patch for the 2.0.x branch, if you like.

renatog’s picture

I can create a patch for the 2.0.x branch, if you like.

Ah amazing @dale42.

Yeaaah, If you can, please

I can commit that for us o/

dale42’s picture

Status: Needs work » Needs review
StatusFileSize
new7.48 KB

Attached is patch file invite-hook-mail-upd-3227581-9.patch with the changes from #3275572.

I tested with the native Drupal mailer and Swift mailer.

renatog’s picture

Status: Needs review » Reviewed & tested by the community

I applied and tested. It really works well

Thanks a lot for your contribution @dale42 and @kalpaitch

  • RenatoG committed 79ac65f on 2.0.x authored by dale42
    Issue #3227581 by kalpaitch, RenatoG, dale42: InviteByEmail $message['...
renatog’s picture

Status: Reviewed & tested by the community » Fixed

Committed to the dev branch.

Thanks a lot

Status: Fixed » Closed (fixed)

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