Every time a form is submitted where the simple hierarchical select widget generates a form error, the following PHP Error is returned:
The website encountered an unexpected error. Please try again later.
Error: Using $this when not in object context in Drupal\shs\Plugin\Field\FieldWidget\OptionsShsWidget::validateElement() (line 355 of modules/contrib/shs/src/Plugin/Field/FieldWidget/OptionsShsWidget.php).
Drupal\shs\Plugin\Field\FieldWidget\OptionsShsWidget::validateElement(Array, Object, Array)
call_user_func_array(Array, Array) (Line: 280)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 236)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 236)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'node_person_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('node_person_form', Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('node_person_form', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
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: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
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: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
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)
Comments
Comment #2
komlenic commentedPatch attached.
Comment #3
komlenic commentedComment #4
komlenic commentedComment #5
nicolabelleriI had the same Problem.
Patch #2 works fine for me, thanks.
Using Drupal 9.2.7
Comment #6
afeijoPatch #2 also worked for me, thanks! I'm also using D9.2.7
Comment #7
dahousecat commentedPatch #2 worked for me on D8.9.19.
Comment #8
komlenic commentedI'm moving this to RTBC due to the simplicity of the change.
Comment #9
stephen-cox commentedPatch works for me on Drupal 8.9.19 and 9.2.7.
Comment #10
seeallie commentedThe same issue occurs in 2.0.0-rc1
Comment #12
stborchertThanks @komlenic for the patch and all the others for testing :)
Comment #14
stephane888 commentedI had the same Problem.
Patch #2 works fine for me, thanks.
Using Drupal 9.2.10
Comment #15
crtlf commentedPatch #2 also working with Drupal 9.3.0.
Thank you !
Comment #16
summit commentedHi, Patch #2 not working using latest SHS dev and drupal 9.3.3, and these patches:
Error status:
Thanks for looking into this.
greetings, Martijn
Comment #17
serverjohn commentedI second @Summit. Patch #2 is not working with Drupal 9.3.3 and SHS 2.0.0-rc1. Applying the patch with Git returns
Skipped patch 'src/Plugin/Field/FieldWidget/OptionsShsWidget.php'.Applying the patch with thepatchcommand just hangs.I manually made the changes in the patch to the
shs/src/Plugin/Field/FieldWidget/OptionsShsWidget.phpfile. This resolved the issue. I have never done a patch before but I am gonna try. BRB.Comment #18
serverjohn commentedIt looks like the latest version of the code has the fix in it. The problem is that the recommended version on the main SHS module page is for 2.0.0-rc1 which does not include the fix.
As a note the same page mentions:
Is it possible to get the recommended version updated to include this fix? Either way use the other version and you won't this problem.
Comment #19
komlenic commentedYes, the module needs a new release to incorporate this and other changes. The changes are necessary to use the module in Drupal 9 on production sites (without resorting to using a dev version).
Comment #20
serverjohn commentedI made a mistake. This patch does work. I didn't execute the patch command properly... :-( There is an additional issue with the same problem. Both resolve the issue. Duplicate: https://www.drupal.org/project/shs/issues/3265197