0 points

Drupal 8 Entity API cheat sheet


dashboard

Thu Oct 29 2020 20:21:43 GMT+0000 (UTC)

Posted by @richard

$query = \Drupal::entityQuery('node')
  ->condition('type', 'article'),
  ->condition('field_foo', 42);
$nids = $query->execute();
$nodes = $node_storage->loadMultiple($nids);
 
foreach ($nodes as $n) {
  echo $n->title->value;            // "Lorem Ipsum..."
 
  // do whatever you would do with a node object (set fields, save, etc.)
  $n->set('title', "this is a test");
  $n->save();
}
content_copy Copy

https://www.metaltoad.com/blog/drupal-8-entity-api-cheat-sheet