Created
January 10, 2018 14:21
-
-
Save Dropa/988edec72ee8efeb4840653461ac339a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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