Problem/Motivation

when trying to access an EndPoint created with rest_views on a content type which contains an entity reference field we get the following error:
Unable to remove item at non-existing index. in Drupal\Core\TypedData\Plugin\DataType\ItemList

The EntityReferenceExportFormatter->view() function tries removing an item from an empty array.

Issue fork rest_views-3472326

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

alina basarabeanu created an issue. See original summary.

alina.basarabeanu’s picture

Issue summary: View changes
StatusFileSize
new693 bytes
alina.basarabeanu’s picture

Status: Active » Needs review

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

vselivanov’s picture

StatusFileSize
new1.18 KB

This is definitely an issue.
But patch #2 works only if you need to remove 1 element.
removeItem() function reassign deltas and for the next elements it won’t work.

The solution should be similar to the jsonapi module from Core:

  1. Collect deltas to remove
  2. Remove them in the desc order.

I tested with the multiple field reference to the paragraphs.
I have 3 paragraphs with 2 unpublished:

$items = [
  0 => 'paragraph-0-unpublished',
  1 => 'paragraph-1',
  2 => 'paragraph-2-unpublished',
];

Unpublished paragraphs are not shown in the $elements after viewElements() and should be removed from the $items

$elements = [
  1 => 'paragraph-1',
];

Created MR and added a patch.

phreaknerd’s picture

Well done.
#6 fixes the issue.

phreaknerd’s picture

Status: Needs review » Reviewed & tested by the community

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

nicxvan’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everyone!

Status: Fixed » Closed (fixed)

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

heddn’s picture

any chance for a new tagged release with this fix?