Skip to content

Instantly share code, notes, and snippets.

@mortenson
Created July 16, 2018 21:34
Show Gist options
  • Save mortenson/c037f2ba745f5b152bdba1b821b6d7ad to your computer and use it in GitHub Desktop.
Save mortenson/c037f2ba745f5b152bdba1b821b6d7ad to your computer and use it in GitHub Desktop.
Dump Drupal nodes as YML
<?php
// Download to Drupal root (where index.php is) and run "drush scr dump.php"
$storage = \Drupal::entityTypeManager()->getStorage('node');
$nodes = $storage->loadMultiple();
echo 'Processing ' . count($nodes) . ' nodes...' . "\n";
/** @var Drupal\node\Entity\Node $node */
foreach ($nodes as $node) {
$path = 'node_dump/' . ltrim(urldecode($node->url()), '/') . '.yml';
file_prepare_directory(dirname($path), FILE_CREATE_DIRECTORY);
echo "Saving node " . $node->id() . " to $path\n";
file_put_contents($path, \Drupal\Core\Serialization\Yaml::encode($node->toArray()));
}
echo "Done!\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment