Problem/Motivation
Submitting a block config form where Attribute Key is specified, but Attribute Value is blank (or vice versa) for an individual attribute, triggers:
The website encountered an unexpected error. Please try again later.
TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in preg_match() (line 1302 of modules/contrib/block_class/src/Service/BlockClassHelperService.php).
preg_match('/['^£$%&*()}{@#~?><>,|=+¬]/', Array) (Line: 1302)
Drupal\block_class\Service\BlockClassHelperService->validateClass(Array, Object, Object) (Line: 913)
Drupal\block_class\Service\BlockClassHelperService->blockClassFormValidate(Array, Object) (Line: 145)
block_class_form_block_form_validate(Array, Object)
call_user_func_array('block_class_form_block_form_validate', Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 275)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'block_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('block_form', Array, Object) (Line: 588)
Drupal\Core\Form\FormBuilder->processForm('block_form', Array, Object) (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
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: 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: 159)
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: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->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: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)Steps to reproduce
- Visit any block config form.
- Provide a value for 'Attribute Key' field, but leave 'Attribute Value' blank (or vice versa).
- Save the block.
Proposed resolution
??
Remaining tasks
- Debug
- Patch
- Test
- Commit
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3320820.patch | 1.08 KB | renatog |
Comments
Comment #2
renatog commentedGood catch, thanks
As solution we can validate on validateAttributes and validateClass methods. Patch with the fix attached
Comment #4
renatog commentedMoved to the dev branch. Thanks @justcaldwell
Comment #5
renatog commentedNew release with that: https://www.drupal.org/project/block_class/releases/2.0.8