Request new confirmation mail is broken

Created on 13 January 2025, 14 days ago

Problem/Motivation

There seems to be a bug in the code which generates the form to request a new confirmation mail. When the button is clicked, an error message occurs and no mail is generated.

Steps to reproduce

  1. Sign up to a newsletter as anonymous user
  2. You'll get a confimation mail with a link you need to click in order to subsribe.
  3. Wait 24 hours or more before clicking the link. The embedded code is now expired and you'll need a new one. Simplenews will show a page with a button "Request new confirmation mail".
  4. Click the button.
  5. EXPECTED: A new confirmation mail with a new link to click. ACTUAL: No mail is generated. Insead, a PHP error "Exception: Unrecognised key confirm in simplenews_mail() (Line 616 in /var/www/html/web/modules/contrib/simplenews/simplenews.module)." happens.
#0 [internal function]: simplenews_mail('confirm', Array, Array)
#1 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(400): call_user_func_array(Object(Closure), Array)
#2 /var/www/html/web/modules/contrib/symfony_mailer/src/Plugin/EmailBuilder/LegacyEmailBuilder.php(124): Drupal\Core\Extension\ModuleHandler->invoke('simplenews', 'mail', Array)
#3 [internal function]: Drupal\symfony_mailer\Plugin\EmailBuilder\LegacyEmailBuilder->build(Object(Drupal\symfony_mailer\Email))
#4 /var/www/html/web/modules/contrib/symfony_mailer/src/Email.php(490): call_user_func(Array, Object(Drupal\symfony_mailer\Email))
#5 /var/www/html/web/modules/contrib/symfony_mailer/src/Mailer.php(179): Drupal\symfony_mailer\Email->process()
#6 /var/www/html/web/modules/contrib/symfony_mailer/src/Mailer.php(149): Drupal\symfony_mailer\Mailer->doSend(Object(Drupal\symfony_mailer\Email))
#7 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\symfony_mailer\Mailer->Drupal\symfony_mailer\{closure}()
#8 /var/www/html/web/modules/contrib/symfony_mailer/src/Mailer.php(158): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#9 /var/www/html/web/modules/contrib/symfony_mailer/src/Email.php(292): Drupal\symfony_mailer\Mailer->send(Object(Drupal\symfony_mailer\Email))
#10 /var/www/html/web/modules/contrib/symfony_mailer/src/MailManagerReplacement.php(92): Drupal\symfony_mailer\Email->send()
#11 /var/www/html/web/modules/contrib/simplenews/src/Form/RequestHashForm.php(79): Drupal\symfony_mailer\MailManagerReplacement->mail('simplenews', 'confirm', 'jane.doe@zebral...', 'de', Array, 'drupal@zebralog...')
#12 [internal function]: Drupal\simplenews\Form\RequestHashForm->submitForm(Array, Object(Drupal\Core\Form\FormState))
#13 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(129): call_user_func_array(Array, Array)
#14 /var/www/html/web/core/lib/Drupal/Core/Form/FormSubmitter.php(67): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#15 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(606): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#16 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm('simplenews_requ...', Array, Object(Drupal\Core\Form\FormState))
#17 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(224): Drupal\Core\Form\FormBuilder->buildForm('\\Drupal\\simplen...', Object(Drupal\Core\Form\FormState))
#18 /var/www/html/web/modules/contrib/simplenews/src/Controller/ConfirmationController.php(87): Drupal\Core\Form\FormBuilder->getForm('\\Drupal\\simplen...', 'confirm', Array)
#19 [internal function]: Drupal\simplenews\Controller\ConfirmationController->confirmSubscribe('6', '1736532312', 'hVxZMHQiWznbKdH...', false)
#20 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#21 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#22 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#23 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#24 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#25 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#26 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /var/www/html/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#34 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#35 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#36 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#37 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#38 {main}

This happens in "RequestHashForm". Line 79 apparently uses the key "confirm", which isn't expected anymore in "simplenews_mail". I think this is built in "ConfirmationController" in line 87:

$build = $this->formBuilder()->getForm('\Drupal\simplenews\Form\RequestHashForm', 'confirm', $context);

This should use "subscribe_combined" instead of "confirm".

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

4.1

Component

Code

Created by

🇩🇪Germany ammaletu Bonn, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ammaletu
  • Merge request !77created mr → (Open) created by Unnamed author
  • Pipeline finished with Failed
    14 days ago
    Total: 504s
    #394396
  • 🇩🇪Germany ammaletu Bonn, Germany

    I created a merge request with the proposed fix. I'm not a 100% sure that this is indeed the best solution. There are still three or four places which use 'confirm' in the module. Changing the key here to 'subscribe_combined' works, I just tested it in the 4.1.0 version. So somebody with a better understanding of how the module works shoudl have a look.

    Also, this might need a test if it could break without anybody noticing. :-) Looking at the existing tests, it seems this would belong into "SimplenewsSubscribeTest". Maybe as a variant of "testSubscribeAnonymous"?!

    Ok, wow, I did not expect someone to work on this within minutes. :-) Should I simple close my MR again?!

  • Pipeline finished with Failed
    14 days ago
    Total: 508s
    #394398
  • 🇬🇧United Kingdom adamps

    adamps changed the visibility of the branch 3499340-request-new-confirmation to hidden.

  • 🇬🇧United Kingdom adamps

    Thanks for the report. The patch looks good. Both MR are the same so I hid the later one (yes please close it). I believe the other uses of 'confirm' are correct (but it's a bit mind-boggling trying to work it all out😃).

    The failing test is unrelated to this issue - it fails anyway due to a change in Core and needs a simple fix.

    Yes it would be great to have a test. If you search the code for 'This link has expired.' you can see 2 places that test expired links. I cannot understand why these tests don't currently fail.

  • 🇬🇧United Kingdom adamps

    I have now fixed the tests on 4.x and merged here so tests are passing.

    Remaining work is for the tests, we need a test that covers this case. Starting point: how come they weren't already failing?

Production build 0.71.5 2024