Webform #Element_validate: Unsupported operand types

Created on 12 June 2023, about 1 year ago
Updated 16 June 2023, about 1 year ago

Problem/Motivation

We are using the Webform Element in a form on our site and we are getting a error on submission. The error is as follows:

TypeError: Unsupported operand types: array + null in Drupal\office_hours\Element\OfficeHoursBaseSlot::validateOfficeHoursSlot() (line 247 of modules/contrib/office_hours/src/Element/OfficeHoursBaseSlot.php).
Drupal\office_hours\Element\OfficeHoursBaseSlot::validateOfficeHoursSlot(Array, Object, Array) (Line: 165)
Drupal\office_hours\Plugin\WebformElement\WebformOfficeHours::validateOfficeHoursSlot(Array, Object, Array)
call_user_func_array(Array, Array) (Line: 282)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'webform_submission_one_to_one_learner_registration__test_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('webform_submission_one_to_one_learner_registration__test_form', Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('webform_submission_one_to_one_learner_registration__test_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'test') (Line: 1249)
Drupal\webform\Entity\Webform->getSubmissionForm(Array, 'test') (Line: 128)
Drupal\webform\Controller\WebformTestController->testForm(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
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: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
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: 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: 718)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

As far as the config options for the element itself, this error persists no matter what options one chooses for it when building the form.

Steps to reproduce

  • Create a webform (or edit an existing form)
  • Add an Office Hours element to the form
  • Attempt a test submission for the form
🐛 Bug report
Status

Fixed

Version

1.11

Component

Code

Created by

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

Comments & Activities

  • Issue created by @LordBarnhill
  • 🇳🇱Netherlands johnv

    How com thisis a new error?
    - new installation,
    - upgrade of PHP version? (What is you current PHP version, since checks are more strict)
    - upgrade of Office hours module?
    working on the problem..

  • Status changed to Needs review about 1 year ago
  • Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
    • johnv committed 4d748dca on 8.x-1.x
      Issue #3366295: #Element_validate: Unsupported operand types: array +...
  • Status changed to Fixed about 1 year ago
  • 🇳🇱Netherlands johnv

    This should be fixed. Please test newest DEV-version, or above patch.

  • Thanks for the quick response! I tested with the patch from #4 🐛 Webform #Element_validate: Unsupported operand types Fixed and got the following error:

    TypeError: Unsupported operand types: bool + array in Drupal\office_hours\Plugin\Field\FieldFormatter\OfficeHoursFormatterBase->mergeDefaults() (line 99 of modules/contrib/office_hours/src/Plugin/Field/FieldFormatter/OfficeHoursFormatterBase.php).
    Drupal\office_hours\Plugin\Field\FieldFormatter\OfficeHoursFormatterBase->mergeDefaults() (Line: 51)
    Drupal\Core\Field\PluginSettingsBase->getSettings() (Line: 45)
    Drupal\office_hours\Plugin\Field\FieldFormatter\OfficeHoursFormatterDefault->viewElements(Object, NULL) (Line: 208)
    Drupal\office_hours\Plugin\WebformElement\WebformOfficeHours->viewElements(Array, Object, Array) (Line: 232)
    Drupal\office_hours\Plugin\WebformElement\WebformOfficeHours->formatTextItem(Array, Object, Array) (Line: 1377)
    Drupal\webform\Plugin\WebformElementBase->format('Text', Array, Object, Array) (Line: 1334)
    Drupal\webform\Plugin\WebformElementBase->formatText(Array, Object, Array) (Line: 356)
    Drupal\webform\Plugin\WebformElement\WebformCompositeBase->formatText(Array, Object, Array) (Line: 1295)
    Drupal\webform\Plugin\WebformElementBase->build('text', Array, Object, Array) (Line: 1274)
    Drupal\webform\Plugin\WebformElementBase->buildText(Array, Object, Array) (Line: 196)
    Drupal\webform\WebformSubmissionViewBuilder->buildElements(Array, Object, Array, 'text') (Line: 193)
    Drupal\webform\Plugin\WebformElement\ContainerBase->formatTextItem(Array, Object, Array) (Line: 1377)
    Drupal\webform\Plugin\WebformElementBase->format('Text', Array, Object, Array) (Line: 1334)
    Drupal\webform\Plugin\WebformElementBase->formatText(Array, Object, Array) (Line: 83)
    Drupal\webform\Plugin\WebformElement\ContainerBase->build('text', Array, Object, Array) (Line: 1274)
    Drupal\webform\Plugin\WebformElementBase->buildText(Array, Object, Array) (Line: 196)
    Drupal\webform\WebformSubmissionViewBuilder->buildElements(Array, Object, Array, 'text') (Line: 1119)
    _webform_token_get_submission_values(Array, Object) (Line: 599)
    webform_tokens('webform_submission', Array, Array, Array, Object)
    call_user_func_array(Object, Array) (Line: 426)
    Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'webform') (Line: 405)
    Drupal\Core\Extension\ModuleHandler->invokeAllWith('tokens', Object) (Line: 433)
    Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array) (Line: 359)
    Drupal\Core\Utility\Token->generate('webform_submission', Array, Array, Array, Object) (Line: 241)
    Drupal\Core\Utility\Token->doReplace(1, 'Submitted on [webform_submission:created]
    Submitted by: [webform_submission:user]
    
    Submitted values are:
    [webform_submission:values]
    ', Array, Array, Object) (Line: 191)
    Drupal\Core\Utility\Token->replace('Submitted on [webform_submission:created]
    Submitted by: [webform_submission:user]
    
    Submitted values are:
    [webform_submission:values]
    ', Array, Array, Object) (Line: 154)
    Drupal\webform\WebformTokenManager->replace('Submitted on [webform_submission:created]
    Submitted by: [webform_submission:user]
    
    Submitted values are:
    [webform_submission:values]
    ', Object, Array, Array, Object) (Line: 173)
    Drupal\webform\WebformTokenManager->replaceNoRenderContext('Submitted on [webform_submission:created]
    Submitted by: [webform_submission:user]
    
    Submitted values are:
    [webform_submission:values]
    ', Object, Array, Array) (Line: 746)
    Drupal\webform\Plugin\WebformHandlerBase->replaceTokens('Submitted on [webform_submission:created]
    Submitted by: [webform_submission:user]
    
    Submitted values are:
    [webform_submission:values]
    ', Object, Array, Array) (Line: 930)
    Drupal\webform\Plugin\WebformHandler\EmailWebformHandler->getMessage(Object) (Line: 857)
    Drupal\webform\Plugin\WebformHandler\EmailWebformHandler->postSave(Object, , NULL) (Line: 2757)
    Drupal\webform\Entity\Webform->invokeHandlers('postSave', Object, , NULL) (Line: 1212)
    Drupal\webform\WebformSubmissionStorage->invokeWebformHandlers('postSave', Object, ) (Line: 1120)
    Drupal\webform\WebformSubmissionStorage->doPostSave(Object, ) (Line: 523)
    Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 804)
    Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 983)
    Drupal\webform\WebformSubmissionStorage->save(Object) (Line: 339)
    Drupal\Core\Entity\EntityBase->save() (Line: 901)
    Drupal\webform\Entity\WebformSubmission->save() (Line: 1995)
    Drupal\webform\WebformSubmissionForm->save(Array, Object)
    call_user_func_array(Array, Array) (Line: 114)
    Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
    Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
    Drupal\Core\Form\FormBuilder->processForm('webform_submission_one_to_one_learner_registration__test_form', Array, Object) (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
    Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'test') (Line: 1249)
    Drupal\webform\Entity\Webform->getSubmissionForm(Array, 'test') (Line: 128)
    Drupal\webform\Controller\WebformTestController->testForm(Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    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: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    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: 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: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    To answer you questions from #3 🐛 Webform #Element_validate: Unsupported operand types Fixed :
    - This is on an existing site, not a new installation
    - The PHP version is 8.1
    - We recently updated the Office Hours module from 8.x-1.8 (I believe) to 8.x-1.9

  • Status changed to Needs review about 1 year ago
  • Status changed to Needs work about 1 year ago
  • 🇳🇱Netherlands johnv

    hmm.

    I guess there is some 'strict_typing' activated by one of your installed modules.
    And as you have only 1 error at a time, this will bounce more often. :-(

    Can you debug and check what is the contents of '$this->settings['exceptions']' ?
    Else, you can save the field formatter settings. That should fix the problem , too. But that is not solution for other people with your settings.

  • The content of $this->settings['exceptions'] is showing to be FALSE.

  • Ahmad Smhan made their first commit to this issue’s fork.

  • Status changed to Needs review about 1 year ago
  • Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • 🇳🇱Netherlands johnv

    Please see attached patch for this new occasion.

    • johnv committed 2512469f on 8.x-1.x
      Issue #3366295 by Ahmad Smhan: #Element_validate: Unsupported operand...
  • Using both the #4 🐛 Webform #Element_validate: Unsupported operand types Fixed and #13 🐛 Webform #Element_validate: Unsupported operand types Fixed patches allowed the form to be submitted successfully. However, now I am seeing an error when trying to view the submission:

    The website encountered an unexpected error. Please try again later.
    TypeError: Drupal\Core\TypedData\TypedDataManager::create(): Argument #1 ($definition) must be of type Drupal\Core\TypedData\DataDefinitionInterface, null given, called in /app/web/modules/contrib/office_hours/src/Plugin/WebformElement/WebformOfficeHours.php on line 384 in Drupal\Core\TypedData\TypedDataManager->create() (line 99 of core/lib/Drupal/Core/TypedData/TypedDataManager.php).
    Drupal\Core\TypedData\TypedDataManager->create(NULL, Array, 'availability', Object) (Line: 384)
    Drupal\office_hours\Plugin\WebformElement\WebformOfficeHours->unserialize(Array, Array, Object) (Line: 194)
    Drupal\office_hours\Plugin\WebformElement\WebformOfficeHours->viewElements(Array, Object, Array) (Line: 219)
    Drupal\office_hours\Plugin\WebformElement\WebformOfficeHours->formatHtmlItem(Array, Object, Array) (Line: 1377)
    Drupal\webform\Plugin\WebformElementBase->format('Html', Array, Object, Array) (Line: 1327)
    Drupal\webform\Plugin\WebformElementBase->formatHtml(Array, Object, Array) (Line: 344)
    Drupal\webform\Plugin\WebformElement\WebformCompositeBase->formatHtml(Array, Object) (Line: 279)
    Drupal\webform\Plugin\WebformElement\WebformCompositeBase->formatTableColumn(Array, Object, Array) (Line: 1001)
    Drupal\webform\WebformSubmissionListBuilder->buildRowColumn(Array, Object) (Line: 834)
    Drupal\webform\WebformSubmissionListBuilder->buildRow(Object) (Line: 219)
    Drupal\Core\Entity\EntityListBuilder->render() (Line: 559)
    Drupal\webform\WebformSubmissionListBuilder->buildEntityList() (Line: 454)
    Drupal\webform\WebformSubmissionListBuilder->render() (Line: 23)
    Drupal\Core\Entity\Controller\EntityListController->listing('webform_submission')
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    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: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    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: 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: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    I am also seeing a warning after submitting the form:

    Warning: Undefined array key "day" in Drupal\office_hours\Element\OfficeHoursBaseSlot::validateOfficeHoursSlot() (line 243 of modules/contrib/office_hours/src/Element/OfficeHoursBaseSlot.php).
    Drupal\office_hours\Element\OfficeHoursBaseSlot::validateOfficeHoursSlot(Array, Object, Array) (Line: 165)
    Drupal\office_hours\Plugin\WebformElement\WebformOfficeHours::validateOfficeHoursSlot(Array, Object, Array)
    call_user_func_array(Array, Array) (Line: 282)
    Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
    Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
    Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
    Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'webform_submission_one_to_one_learner_registration__test_form') (Line: 118)
    Drupal\Core\Form\FormValidator->validateForm('webform_submission_one_to_one_learner_registration__test_form', Array, Object) (Line: 593)
    Drupal\Core\Form\FormBuilder->processForm('webform_submission_one_to_one_learner_registration__test_form', Array, Object) (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
    Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'test') (Line: 1249)
    Drupal\webform\Entity\Webform->getSubmissionForm(Array, 'test') (Line: 128)
    Drupal\webform\Controller\WebformTestController->testForm(Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    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: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    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: 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: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
  • Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • 🇳🇱Netherlands johnv

    Unfortunately, I cannot reproduce your problem, working with Drupal 9.5.x and latest Webform version and PHP8.2.

    Yesterday, a new version 1.11 is released. Please test again with that release.

    Please also see attached new patch, regarding Warning: Undefined array key "day" . I will commit that change shortly.

    I created Webformsubmissions from beow pages, and none call the viewElements() function. Only prepare() is called.
    /form/TYPE
    /webform/TYPE/test

    Can you state your complete test script? I think is is used when downloading webform submissions.

    • johnv committed fe26c7e4 on 8.x-1.x
      Issue #3366295: Warning: Undefined array key 'day' in...
  • 🇳🇱Netherlands johnv

    OK, your error appears on the following page:
    admin/structure/webform/manage/TYPE/results/submissions

  • Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
  • 🇳🇱Netherlands johnv

    Please test attached patch.
    Or download dev, since I will commit it shortly.

  • Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Waiting for branch to pass
    • johnv committed 055745e6 on 8.x-1.x
      Issue #3366295: WebformOfficeHours->unserialize error
      
    • johnv committed ee0317b7 on 8.x-1.x
      Issue #3366295: WebformOfficeHours refactoring
      
    • johnv committed 03dac3d0 on 8.x-1.x
      Issue #3366295: WebformOfficeHours->viewElements() refactoring
      
  • I tested with the newest version (v1.11) and the patches from #16 🐛 Webform #Element_validate: Unsupported operand types Fixed and #20 🐛 Webform #Element_validate: Unsupported operand types Fixed and all the errors seem to be resolved! I am now able to submit the form successfully and view the submissions at admin/structure/webform/manage/TYPE/results/submissions. Thank you for being so responsive with this issue!

  • 🇳🇱Netherlands johnv

    De nada.

  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024