Using $error->arrayPropertyPath returns empty everytime

Created on 11 May 2023, over 1 year ago

Problem/Motivation

Hello, so after this patch was committed to Drupal core Using ConstraintViolation::$arrayPropertyPath bugs on PHP 8.2 β†’

  /**
   * {@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.
    if (!empty($error->arrayPropertyPath) && $sub_element = NestedArray::getValue($element, $error->arrayPropertyPath)) {
      return $sub_element;
    }
    return $element;
  }

This code from paragraphs stops working, and you can never reach $sub_element, because !empty($error->arrayPropertyPath condition every time returns false, even if a value is not empty.

Steps to reproduce

1. Install paragraphs
2. Apply the patch https://www.drupal.org/project/paragraphs/issues/2994660 ✨ Add a support of targeting subelements during validation Needs work
3. In ConstraintValidator set path ->atPath() to the nested element.
4. !empty($error->arrayPropertyPath) will return false.

Proposed resolution

Add this code to make it work.

  /**
   * {@inheritdoc}
   */
  public function __isset($name) {
    return isset($this->$name);
  }
πŸ› Bug report
Status

Active

Version

10.1 ✨

Component
FormΒ  β†’

Last updated about 24 hours ago

Created by

πŸ‡ΊπŸ‡¦Ukraine Mokys

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024