Skip to content

Instantly share code, notes, and snippets.

@arpitr
Created December 31, 2020 05:14
Show Gist options
  • Save arpitr/e223ce73496d64ad38dd486f70d70a23 to your computer and use it in GitHub Desktop.
Save arpitr/e223ce73496d64ad38dd486f70d70a23 to your computer and use it in GitHub Desktop.
Attach media to all article nodes
// replace 119751 with media entity ID
drush php-eval '$nids = \Drupal::entityQuery("node")->condition("type","article")->execute();$nodes = \Drupal\node\Entity\Node::loadMultiple($nids);$media = \Drupal\media\Entity\Media::load(119751);foreach($nodes as $node) {$node->field_hero_media->entity = $media;$node->save();}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment