Webform Element: InvalidArgumentException: $string ("Office hours") must be a string

Created on 14 June 2022, over 2 years ago
Updated 11 November 2024, about 2 months ago

Problem/Motivation

There is an issue trying to add a new Element in Webforms.
Trying to add a new element I detected that the modal doesn't open anymore and in console was showing an error 500.

Using Chrome browser, I inspected the error in Network tab getting the details about the error:

The website encountered an unexpected error. Please try again later.

InvalidArgumentException: $string ("Office hours") must be a string. in Drupal\Core\StringTranslation\TranslatableMarkup->__construct() (line 132 of core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php).
Drupal\Core\Plugin\PluginBase->t(Object) (Line: 100)
Drupal\office_hours\Plugin\Field\FieldWidget\OfficeHoursWeekWidget->formElement(Object, 0, Array, Array, Object) (Line: 116)
Drupal\office_hours\Plugin\WebformElement\WebformOfficeHours->prepare(Array, Object) (Line: 299)
Drupal\webform_ui\Form\WebformUiElementTypeFormBase->buildElementPreview(Object) (Line: 237)
Drupal\webform_ui\Form\WebformUiElementTypeFormBase->buildRow(Object, Object, Object) (Line: 78)
Drupal\webform_ui\Form\WebformUiElementTypeSelectForm->buildForm(Array, Object, Object)
call_user_func_array(Array, Array) (Line: 531)
Drupal\Core\Form\FormBuilder->retrieveForm('webform_ui_element_type_select_form', Object) (Line: 278)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 265)
Drupal\shield\ShieldMiddleware->bypass(Object, 1, 1) (Line: 132)
Drupal\shield\ShieldMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

I just updated to the latest version 8.x-1.6 using composer and was not able to add elements in new and existing webforms.

Proposed resolution

The error is related to `TranslatableMarkup`.
I detected the issue specifically in this file: `OfficeHoursWeekWidget` line 100 & 126

The proposed solution I'm leaving in a patch file (attached).

Remaining tasks

Needs community review.

🐛 Bug report
Status

Fixed

Version

1.6

Component

Code - widget

Created by

🇪🇨Ecuador afsch Otavalo

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024