Problem/Motivation
Hello. When adding a violation for a delta of a text field with summary, the form error rendering ends in an exception.
The issue is that the text_textarea_with_summary
widget always assumes that the property path contains at least two elements (e.g., 0.value
, 0.summary
).
But when a violation is added to a field delta directly (e.g., just 0
), the widget fails.
There’s no documentation stating that the violation must target a specific sub-property like value
or summary
.
This is likely a bug, because a related field type - text_long
with the text_textarea
widget - handles such cases correctly without throwing an error.
I’m aware of the
🌱
[Meta] Deprecate text_with_summary
Active
issue, which proposes to deprecate the text_with_summary
field type and move it to contrib:
2. Move the field type, formatter and widget to a module
3. Deprecate the module and move it to contrib
However, since the text_textarea_with_summary
widget is still in use and this is a runtime exception triggered during validation, I believe it should still be fixed.
Backtrace:
The website encountered an unexpected error. Try again later.
TypeError: Drupal\Core\Form\FormState::setError(): Argument #1 ($element) must be of type array, null given, called in /var/www/core/lib/Drupal/Core/Field/WidgetBase.php on line 587 in Drupal\Core\Form\FormState->setError() (line 1157 of core/lib/Drupal/Core/Form/FormState.php).
Drupal\Core\Field\WidgetBase->flagErrors(Object, Object, Array, Object) (Line: 289)
Drupal\Core\Entity\Entity\EntityFormDisplay->flagWidgetsErrorsFromViolations(Object, Array, Object) (Line: 268)
Drupal\Core\Entity\ContentEntityForm->flagViolations(Object, Array, Object) (Line: 214)
Drupal\Core\Entity\ContentEntityForm->validateForm(Array, Object)
call_user_func_array(Array, Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 275)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'node_page_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('node_page_form', Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('node_page_form', Array, Object) (Line: 321)
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: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 36)
Drupal\Core\Test\StackMiddleware\TestWaitTerminateMiddleware->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)
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: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 715)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Steps to reproduce
- Create a text field with summary enabled.
- Add a constraint to the field that triggers a violation on a field delta (e.g.,
UniqueField
) or apply a constraint at the FieldType
plugin level.
- Trigger validation to surface the error.
Proposed resolution
It appears that the widget is attempting to highlight errors for both value
and summary
separately.
I propose that when the violation’s property path contains only the delta (no sub-property), the widget should mark the entire widget element as the error target.
This prevents exceptions and allows general validation errors on the whole field to display correctly.
Remaining tasks
- Add a test case.
- Fix the bug.
User interface changes
None.
Introduced terminology
None.
API changes
None.
Data model changes
None.
Release notes snippet
None.