Ajax error on delete item

Created on 2 November 2021, about 3 years ago
Updated 21 March 2023, over 1 year ago

Problem/Motivation

When try to delete a item, get an ajax error:
Object { message: "\nAn AJAX HTTP error occurred.\nHTTP Result Code: 200\nDebugging information follows.\nPath: /node/9391/edit?destination=/admin/content&ajax_form=1\nStatusText: OK\nResponseText: Notice: Undefined offset: -1 in /app/web/modules/contrib/entity_browser/src/Plugin/Field/FieldWidget/EntityReferenceBrowserWidget.php on line 817

Steps to reproduce

- Select an item (video on my case) on the entity browser.
- Save the node.
- Edit the node and try to delete the item.

Proposed resolution

The error comes from this lines:

$field_name_key = end($trigger['#parents']) === 'target_id' ? 2 : static::$deleteDepth + 1;
$field_name_key = count($trigger['#parents']) - $field_name_key;

The $field_name_key result as -1, which is incorrect for field index on next line:
$is_relevant_submit &= ($trigger['#parents'][$field_name_key] === $this->fieldDefinition->getName())

Just add a validation to avoid negative value on the field index:

if ($field_name_key < 0 ) {
  $field_name_key = 0;
}
πŸ› Bug report
Status

Active

Version

2.6

Component

Field widget

Created by

πŸ‡¦πŸ‡·Argentina SiroAusili Buenos Aires

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.

  • πŸ‡ΊπŸ‡ΈUnited States cbfannin
  • Status changed to Needs review 4 months ago
  • πŸ‡ΊπŸ‡ΈUnited States cbfannin

    I did a clean install on simplytest.me with 8.x-2.6 and not seeing this issue.

    My test steps were:
    - Installed 8.x-2.6 (unpatched)
    - Created a new Entity Browser adding the upload widget.
    - Added an entity reference field to the page node type.
    - Set the entity reference field's form display to Entity Browser.
    - Created a new node.
    - Selected an image with the new field.
    - Saved the node.
    - Edited the node.
    - Clicked the "Removed" button.
    Result: The image was removed with no reported errors.

    Again this was a clean install with no patches.
    If anyone wants to provide their test steps, I am more than happy to test again.

  • πŸ‡¬πŸ‡§United Kingdom grahamC Oxford, UK

    We're seeing the same issue. It doesn't actually cause a problem unless PHP has the display_errors option switched on.

    Here the problem is caused by having both an Entity Browser field and a core Media Library field on the same form. When trying to remove an item from the media widget, the Entity Browser code is getting confused because the button for core Media Library is also called remove_button

    Attaching patch which checks the field name on the triggering element matches the expected one for this widget. This allows both the media library and entity browser to function correctly again here.

Production build 0.71.5 2024