refactor: extract a variable for node storage

This commit is contained in:
Oliver Davies 2022-02-08 12:00:00 +00:00
parent 80cfdbf133
commit 915347a7a8

View file

@ -49,14 +49,16 @@ Loading entities by properties
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
$nodeStorage = \Drupal::entityTypeManager()->getStorage('node');
// Load all published `event` nodes. // Load all published `event` nodes.
\Drupal::entityTypeManager()->getStorage('node')->loadByProperties([ $nodeStorage->loadByProperties([
'status' => NodeInterface::PUBLISHED, 'status' => NodeInterface::PUBLISHED,
'type' => 'event', 'type' => 'event',
]); ]);
// Load all published `talk` nodes. // Load all published `talk` nodes.
\Drupal::entityTypeManager()->getStorage('node')->loadByProperties([ $nodeStorage->loadByProperties([
'status' => NodeInterface::PUBLISHED, 'status' => NodeInterface::PUBLISHED,
'type' => 'talk', 'type' => 'talk',
]); ]);
@ -68,11 +70,13 @@ Returns an instance of ``Drupal\Core\Entity\Query\QueryInterface`` for the speci
.. code:: php .. code:: php
// Load all node IDs. $nodeStorage = \Drupal::entityTypeManager()->getStorage('node');
\Drupal::entityTypeManager()->getStorage('node')->getQuery()->execute();
// Load node IDs that match the specified conditions. // Load all nodes.
\Drupal::entityTypeManager()->getStorage('node')->getQuery() $nodeStorage->getQuery()->execute();
// Load nodes that match the specified conditions.
$nodeStorage->getQuery()
->condition('type', 'event') ->condition('type', 'event')
->condition('title', '%Online%', 'LIKE') ->condition('title', '%Online%', 'LIKE')
->range(0, 10) ->range(0, 10)