Entity Query Decorator for easy Entity Queries

cough I was asked to chime in ...

  1. While it is true the check results - load stuff - iterate over entities is a common pattern and a wrapper perhaps would indeed be useful, that would look like foreach (Helper::iterator($query) as $entity) saving the if-check. One could even argue that the Entity::load function throwing a warning when passed an empty array is a bug and fixing that would be the easiest. Writing a new query language is not a wise idea IMO

  2. Mixing in common entity operations into the same service is IMO not best practice either. Indeed Drupal 8 entities support toArray() without any other special thing: just $entity->toArray() works. Extracting a field is just $entity->toArray()['fieldname'] and if it is like an entity reference then array_column($entity->toArray()['fieldname'], 'target_id') will give you a list of target IDs. For multiple helpers wrapping this in a helper might be useful, yes but again, not baked into the entity query itself.

Hope this is helpful and I'd be glad to give more --unasked for :P-- advice.

/r/drupal Thread Link - drupal.org