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

  1. Visit any block config form.
  2. Provide a value for 'Attribute Key' field, but leave 'Attribute Value' blank (or vice versa).
  3. Save the block.

Proposed resolution

??

Remaining tasks

  • Debug
  • Patch
  • Test
  • Commit
CommentFileSizeAuthor
#2 3320820.patch1.08 KBrenatog

Comments

justcaldwell created an issue. See original summary.

renatog’s picture

StatusFileSize
new1.08 KB

Good catch, thanks

As solution we can validate on validateAttributes and validateClass methods. Patch with the fix attached

  • 90313f1 committed on 2.0.x
    Issue #3320820 by RenatoG, justcaldwell: Fatal error if one attribute...
renatog’s picture

Status: Active » Fixed

Moved to the dev branch. Thanks @justcaldwell

renatog’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.