PHP Warning break ajax requests (Layout Builder)

Created on 16 January 2023, almost 2 years ago
Updated 4 December 2023, 12 months ago

When in layout builder add new block then ajax requre fail because it have warning contents in response

Warning: Undefined array key "unique" in Drupal\machine_name\Plugin\Validation\Constraint\MachineNameUniqueValidator->validate() (line 57 of contrib\machine_name\src\Plugin\Validation\Constraint\MachineNameUniqueValidator.php).:

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine cosolom

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡·Argentina abelpzl

    I had the same problem without using the Layout Builder module and I solved it by applying #2.
    Can someone merge this? how can I help?

  • Status changed to RTBC 12 months ago
  • Status changed to Needs review 12 months ago
  • πŸ‡ΊπŸ‡¦Ukraine abramm Lutsk
  • Status changed to RTBC 12 months ago
  • πŸ‡ΊπŸ‡¦Ukraine cosolom

    @abramm why you don't want to merge this code? It's not new logic or condition. This is a simple additional part how a good PHP code should have. You can't just check element of array with ! sign if you don't really know if this variable exists. You can use !empty or (isset & have value) or ?? for set default value for suppress PHP warning. It should't even be covered with tests.

  • πŸ‡ΊπŸ‡¦Ukraine abramm Lutsk

    Hi cosolom,

    Please don't change the status to RTBC as there are no community reviews; you've changed the status for your own code.

    As for the approach you've taken, the problem is that you've fixed the symptom rather than root cause of the issue; the unique setting should be always present for the field. Not having it is likely a problem and the way you've fixed it is just by ignoring it.

    I appreciate your patch and I'd like to keep it here so people could use it as workaround if they happen to have the same issue but unfortunately that's not the fix for a root cause.

  • Status changed to Needs review 12 months ago
  • πŸ‡ΊπŸ‡¦Ukraine cosolom

    I think that even unique setting is missed - we can add error message to log and don't break Ajax request at all. This will increase stability for the project.

Production build 0.71.5 2024