Situation:
+- 9000 users

Entity type with entity reference field of entity type "user". The reference type used is "views"
Form display with Widget Select2: autocomplete on - "contains"

Problem:
When the select2 widget is initialised on the form, we get a "Fatal error: Allowed memory size exhausted in /var/www/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php on line 1276".
This is because the select2 widget will fetch all results from the view, without pagination and thus results in a load of +- 9000 users which is a bit much.

(possible) Solution:
The Select2 widget will look for all valid referenceable Entities.
This happens in the Element/Select2.php file on line 186. There we should find something to override the default behavior because now it acts more or less like a default select element where this issue would also be the case, hence the lazy load that is needed.

Comments

ReBa created an issue. See original summary.

ReBa’s picture

Issue summary: View changes
ReBa’s picture

I've solved it by checking if the $ids array is empty or not.
This way, the validation only occurs on the entity ids that are provided and the huge list validation is ignored.

Patch tested against 1.5 version and 1.x-dev version.
Can someone review?

chr.fritsch’s picture

Status: Active » Needs review

chr.fritsch credited Murz.

chr.fritsch’s picture

chr.fritsch’s picture

Crediting @mtodor for his review

  • chr.fritsch authored 66d5286 on 8.x-1.x
    Issue #3105844 by ReBa, chr.fritsch, Murz, mtodor: Entity reference of...
chr.fritsch’s picture

Status: Needs review » Fixed

Merged

Status: Fixed » Closed (fixed)

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

chucksimply’s picture

Doesn't look like this patch has been committed to the latest prod version - 8.1.13 yet. Still need to apply the patch manually.