- π¨πSwitzerland tcrawford
ParagraphsWidget::errorElement() attempts to get the sub element when the path is valid. It currently checks for empty($this->arrayPropertyPath) where arrayPropertyPath is got via magic on Drupal\Core\Field\InternalViolation, but InternalViolation does not implement __isset(). Therefore the code on errorElement never returns $sub_element, even if there is a valid sub element found by NestedArray::getValue(). We could open an issue in core for InternalViolation to implement __isset(), but likely that won't move forward as accessing arrayPropertyPath via magic is deprecated. Therefore, I would propose the following solution (patch to follow):
?> /** * {@inheritdoc} */ public function errorElement(array $element, ConstraintViolationInterface $error, array $form, FormStateInterface $form_state) { // Validation errors might be a about a specific (behavior) form element // attempt to find a matching element. // A temporary variable needed as arrayPropertyPath is accessed via magic // and Drupal\Core\Field\InternalViolation does not implement __isset. // Therefore, empty($error->arrayPropertyPath) returns true even when the // magic getter returns a value. $arrayPropertyPath = $error->arrayPropertyPath; if (!empty($arrayPropertyPath) && $sub_element = NestedArray::getValue($element, $error->arrayPropertyPath)) { return $sub_element; } return $element; }
- Status changed to Needs review
over 1 year ago 9:18am 30 June 2023 - last update
over 1 year ago 180 pass - last update
over 1 year ago 159 pass, 12 fail - π§πͺBelgium herved
Hi @robpowell, @tcrawford,
It would be great if you could check out the patch in π Stop using $error->arrayPropertyPath Needs review which should fix both issues (this one + the deprecation of arrayPropertyPath), so we could close this as duplicate.
Thanks
- Status changed to Postponed: needs info
5 months ago 10:47pm 6 August 2024 - π¨πSwitzerland berdir Switzerland
The referenced issue is now committed. Could still use this to add test coverage.