Skip to content

Instantly share code, notes, and snippets.

@Dropa
Created January 10, 2018 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dropa/988edec72ee8efeb4840653461ac339a to your computer and use it in GitHub Desktop.
Save Dropa/988edec72ee8efeb4840653461ac339a to your computer and use it in GitHub Desktop.
<?php
$entityTypeManager = \Drupal::entityTypeManager();
$storage = $entityTypeManager->getStorage('node');
// Replace <article> with your nodetype.
$query = $storage->getQuery()
->condition('type', 'article')
->execute();
// Chunk in case you have thousands of nodes to update.
foreach (array_chunk($query, 200) as $chunk) {
/* @var \Drupal\node\NodeInterface[] $nodes */
$nodes = $storage->loadMultiple($chunk);
foreach ($nodes as $node) {
// Replace <status> with your field.
$node->set('status', TRUE);
$node->save();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment