Problem/Motivation

At saving an entity using a vat_number field, this warning is raised:

Warning : Undefined array key "#webform_key" dans Drupal\vat_number\Element\VatNumber::validateVatNumber() (/var/www/html/web/modules/contrib/vat_number/src/Element/VatNumber.php ligne 37)

followed by this error:

TypeError: Drupal\Component\Utility\NestedArray::setValue(): Argument #1 ($array) must be of type array, string given, called in /var/www/html/web/core/lib/Drupal/Core/Form/FormStateValuesTrait.php on line 46 in Drupal\Component\Utility\NestedArray::setValue() (line 147 of /var/www/html/web/core/lib/Drupal/Component/Utility/NestedArray.php).

Steps to reproduce

Use an entity with vat_number field. Create an entity or save an existing entity with a vat number.

Proposed resolution

The fix is to replace the setValue() call with setValueForElement(), which is the correct API for element validators — it uses $element['#parents'] (always present) instead of the webform-specific #webform_key.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork vat_number-3589690

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

xdequinze created an issue. See original summary.

xdequinze’s picture

Issue summary: View changes
xdequinze’s picture

This patch fixes my issue.

dieterholvoet made their first commit to this issue’s fork.

  • dieterholvoet committed 34d0e91a on 2.0.x
    fix: #3589690 Undefined array key "#webform_key" dans Drupal\vat_number\...
dieterholvoet’s picture

Status: Active » Fixed

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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