Entity Query Decorator
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Downloads
Component created
Component changed
Component body
Entity query decorator is a Drupal 8 wrapper around the Entity Query class to make querying entities even easier. Whenever using entity queries you generally always end up in the same scenario: Executing your query, checking for results, loading the entities, looping through the entities and then obtaining a value you want. This module sets out to simplify that process by providing a decorator class to combine those steps together.
Finding a node by a field
$entities = Drupal::service('eqd')
->getStorage('node')
->findBy(array('title' => 'My blog post'))
->load();
In this example we execute an entity query and find the node, then load the node. The result is the actual node object.
Loading only specific values
$entities = Drupal::service('eqd')
->getStorage('node')
->findBy(array('title' => 'My blog post'))
->getValues(array('field_my_field', 'field_other_field'));
This example you will gather the values of the entity fields and skip the step of looping through to find these values.
Get all values of a node as an array
$entities = Drupal::service('eqd')
->getStorage('node')
->findBy(array('title' => 'My blog post'))
->getEntitiesArray();
Drupal 8 nodes have a method to get all the values of a node as an array. You can execute the method about to gather all information about that node into an array format.
** Note: this current version only supports the = operator on entity queries.
Later versions will provide more functionality **
