The Y project provides a function
Here is another example using query variables to get a paged (
The Entity query builder relies on YAD7 / Drupal-7's native EntityFieldQuery class, so all methods defined by that class are supported.
y__query()
which performs arbitrary queries based on a query definition.
To query a database for recent nodes
of type article
create a file called examplequery_allnodes.yaml
in your Y module's config/query
directory and put these contents in it.
entity:
new: node
build:
- entityCondition: [ bundle, article ]
- propertyCondition: [ status, TRUE ]
- propertyOrderBy: [ created, DESC ]
- pager: [ 12 ]
Then, in your PHP code, put a line looking like:
$recent_nodes = y__query( 'examplequery_allnodes', 'query', 'Entity', 'examplemodule' );
Here is another example using query variables to get a paged (
pagesize
) list of all nodes of type contenttype
tagged (by Drupal taxonomy term field fieldname
) with any of a list of terms (array termlist
):
entity:
new: node
build:
- entityCondition: [ bundle, //$contenttype ]
- fieldCondition: [ //$fieldname, tid, //$termlist, IN ]
- propertyOrderBy: [ created ]
- pager: [ //$pagesize ]
The Entity query builder relies on YAD7 / Drupal-7's native EntityFieldQuery class, so all methods defined by that class are supported.
12 / 2021