The \Drupal\search_api\Item\Item class (like others) has a __toString() method that allows developers to easily see the contents of an item for debugging purposes. (A usage facing end users doesn’t seem reasonable, I’d say.)
This string representation also includes the item’s fields, but instead of only printing those that are currently part of the item object (as would seem reasonable and expected, at least in my opinion) we do $this->getFields(), which extracts all the item’s fields to print them. The code suggests that this is merely by accident, too. In any case, while the performance cost doesn’t really seem relevant in the case of a DX feature that won’t be used in production anyways, I don’t think anyone expects a __toString() method with side effects, but to just have the item printed in its current form. (Explicitly extracting the field values beforehand, if needed, is the matter of a single method call.)

So, I propose changing those calls to $this->getFields(FALSE).

CommentFileSizeAuthor
#3 no-extract-3059070.patch614 bytesfconnolly

Comments

drunken monkey created an issue. See original summary.

borisson_’s picture

Issue tags: +Novice

I don’t think anyone expects a __toString() method with side effects, but to just have the item printed in its current form.

100% agree. Should be an easy fix (since it's just changing that method call). Tagging as novice.

fconnolly’s picture

StatusFileSize
new614 bytes
fconnolly’s picture

Status: Active » Needs review
borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Yes, this looks like what we needed from this issue, thanks!

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Yes, looks good! Thanks for providing the patch!
Committed.
And a round of cheap contrib credits for everyone! \o/ ;)

Status: Fixed » Closed (fixed)

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