Problem/Motivation
The translations page of a webform ( /admin/structure/webform/manage/webform_id/translate/langcode/edit ) crashes with an error if a custom email handler is enabled in the webform.
Steps to reproduce
Create a custom webform handler:
use Drupal\webform\Plugin\WebformHandler\EmailWebformHandler;
/**
* Test custom webform handler
*
* @WebformHandler(
* id = "custom_webform_handler",
* label = @Translation("Custom webform handler"),
* category = @Translation("Custom webform handler"),
* description = @Translation("Test webform handler."),
* cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_UNLIMITED,
* results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
* submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_OPTIONAL,
* tokens = TRUE,
* )
*/
class CustomWebformHandler extends EmailWebformHandler {
}
Add and enable it in your webform under admin/structure/webform/manage/webform_id/handlers , then fill in the required fields in the settings.
You can see that the handlers list page does not show the configuration of this handler, the same way that a normal email handler would show it (it is missing for example: To, From, Subject, Settings, Sent when). This issue existed also when I was on version 6.0.1.
You open the webform translation page ( /admin/structure/webform/manage/webform_id/translate/langcode/edit ) and it crashes with an error. This part was fine when I was on version 6.0.1 though it could be that the reason is not the webform module upgrade. The error looks like this:
TypeError: Argument 1 passed to Drupal\webform\WebformTranslationConfigManager::alterTextareaElement() must be of the type array, null given, called in /var/www/html/web/modules/contrib/webform/src/WebformTranslationConfigManager.php on line 336 in Drupal\webform\WebformTranslationConfigManager->alterTextareaElement() (line 895 of /var/www/html/web/modules/contrib/webform/src/WebformTranslationConfigManager.php)
#0 /var/www/html/web/modules/contrib/webform/src/WebformTranslationConfigManager.php(336): Drupal\webform\WebformTranslationConfigManager->alterTextareaElement(NULL, 'twig')
#1 /var/www/html/web/modules/contrib/webform/src/WebformTranslationConfigManager.php(237): Drupal\webform\WebformTranslationConfigManager->alterConfigWebformFormHandlers('webform.webform...', Array, Array, Object(Drupal\Core\Form\FormState))
#2 /var/www/html/web/modules/contrib/webform/src/WebformTranslationConfigManager.php(128): Drupal\webform\WebformTranslationConfigManager->alterConfigWebformForm('webform.webform...', Array, Array, Object(Drupal\Core\Form\FormState))
#3 /var/www/html/web/modules/contrib/webform/includes/webform.translation.inc(75): Drupal\webform\WebformTranslationConfigManager->alterForm(Array, Object(Drupal\Core\Form\FormState))
#4 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(539): webform_form_config_translation_edit_form_alter(Array, Object(Drupal\Core\Form\FormState), 'config_translat...')
#5 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(836): Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object(Drupal\Core\Form\FormState), 'config_translat...')
#6 /var/www/html/web/core/lib/Drupal/Core/Form/FormBuilder.php(279): Drupal\Core\Form\FormBuilder->prepareForm('config_translat...', Array, Object(Drupal\Core\Form\FormState))
#7 /var/www/html/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\config_translation\Form\ConfigTranslationEditForm), Object(Drupal\Core\Form\FormState))
#8 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#9 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#10 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#11 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#12 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#13 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#14 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#15 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /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)
#19 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(706): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#24 {main}
In practice in the alterConfigWebformFormHandlers() method in the $config_element the handler with $handler_id == 'custom_webform_handler' does not have any settings for it, unlike a normal email handler (without a custom subclass) would.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 3215471-webform.patch | 573 bytes | raminu |
| #3 | 3215471-3.patch | 1.61 KB | jrockowitz |
Comments
Comment #2
jrockowitz commentedComment #3
jrockowitz commentedComment #4
nikolay.m commentedHello, and thank you @jrockowitz so much for pushing a patch so fast!
I tried the patch from #3 and loading the translation interface succeeds. However, when I press the save button it gets a different kind of error:
On the translation page when I preview my email handlers that don't use a custom class they have a lot of extra things that can be translated, compared to my email handlers that use a custom class. That's not a big issue to me at least though so I liked your approach that the attempt is to simply get the translation interface to work again.
Comment #5
jrockowitz commentedI am not able to replicate that issue because it is coming from custom code.
If you can post a very simple example module that can be used to replicate this issue, I should be able to fix it.
Comment #6
antoniya commentedAlso hitting this on 6.0.3 with one custom handler for multiple webforms. The patch in #3 helps work around the issue, I was able to edit a webform translation and save it. Thanks @jrockowitz!
Comment #7
paulocsHallo @antoniya?
Could you please post a simple module with the
EmailWebformHandlerso we can be able to reproduce the error?Cheers, Paulo.
Comment #8
antoniya commentedhi @paulocs, you can easily reproduce the error using the example email handler from this page.
It looks like some code was added recently to improve the UX of the translation form in https://www.drupal.org/node/3202515. In my case, the form crashes on WebformTranslationConfigManager::alterHtmlEditorElement (line 340), so just a few lines later than the usage of WebformTranslationConfigManager::alterTextareaElement (which is the original report of this issue).
For what I can tell so far is that
$config_element['handlers'][$handler_id]in custom handlers doesn't have a 'settings' key and so$body_elementends up being NULL for those (s. usage ofDrupal\Component\Utility\NestedArrayon line 333).Here's the exact error message for the sake of completeness:
Comment #9
jrockowitz commentedSince the main issue issue is resolved via the patch, I committed it. Please create a new ticket for the second issue from #4.
Comment #12
raminu commentedThis patch fixes it
Comment #13
raminu commentedQuick-fixed it with this by removing webformToken function's last parameter type checking.
Comment #14
guillaumeduveauWith 6.0.5, in which this patch is included, I still have the original issue of the settings summary not appearing. I must add a hook_token and a template for it to appear.
As for the translation page, it does not crash, but there's no Email accordion with the settings. Guess I must add a .yml file for the config translation as well.