- πͺπͺEstonia pjotr.savitski
It seems that there is an issue with the current code that prevents a certain field form being targeted.
The issue is with the
!empty($error->arrayPropertyPath)
check of the errorElement method that will return false regardless of the real value of arrayPropertyPath property that seems to be fetched through the magic __get method. The solution could be either to define a local variable and use that instead or use the getPropertyPath method instead.The resulting code would be either
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. $path = $error->arrayPropertyPath; if (!empty($path) && $sub_element = NestedArray::getValue($element, $path)) { return $sub_element; } return $element; }
or
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. if (!empty($error->getPropertyPath()) && $sub_element = NestedArray::getValue($element, $error->arrayPropertyPath)) { return $sub_element; } return $element; }
- Merge request !95Fixed an issue with empty check not functioning as it is suppose to. Changed... β (Open) created by pjotr.savitski
- last update
9 months ago 182 pass - πΊπ¦Ukraine Mokys
Hello, you can use "combine" with this patch to make it work. It adds magic method that was removed in the new version of Drupal.
https://www.drupal.org/project/drupal/issues/3359645 π Using $error->arrayPropertyPath returns empty everytime Active
- Status changed to Closed: duplicate
2 months ago 5:57pm 20 September 2024 - π¨π¦Canada tame4tex
I believe this has been fixed by Stop using $error->arrayPropertyPath (3333974) β and is in release 1.18. Thus I am closing as duplicate.