Skip to content

Instantly share code, notes, and snippets.

@adamfranco
Last active August 3, 2018 15:05
Show Gist options
  • Save adamfranco/3347950b29d437474aad33dc18f1b3f9 to your computer and use it in GitHub Desktop.
Save adamfranco/3347950b29d437474aad33dc18f1b3f9 to your computer and use it in GitHub Desktop.
$nids = \Drupal::entityQuery('node')->condition('type', 'event')->condition('status', 0)->execute();
$nodes = entity_load_multiple('node', $nids);
foreach ($nodes as $entity) {
$entity->set('moderation_state', 'published');
if ($entity instanceof RevisionLogInterface) {
$entity->setRevisionLogMessage('Programatically updating workflow state.');
$entity->setRevisionUserId(\Drupal::currentUser()->id());
}
$entity->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment