Last active
September 18, 2019 14:45
-
-
Save GuyPaddock/29c8f872b79235ecb0cb10352e53d9dc to your computer and use it in GitHub Desktop.
Resurrecting an Unsaved Drupal 8 Node from the Database using Devel
This file contains hidden or 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 | |
// NOTE: Node previews expire after 7 days. Be sure to use this method to extract the desired data before then. | |
// IMPORTANT: Set this to the user ID of the person who was creating/lost the node. | |
$user_id = 1; | |
// IMPORTANT: Set this to the UUID that appeared in the node preview URL. | |
// This value is from a URL that looked like this: | |
// https://my-site/node/preview/ed4eaac0-3c32-427e-860f-6ce8fc79c3b2/full | |
$preview_id = 'ed4eaac0-3c32-427e-860f-6ce8fc79c3b2'; | |
$user = user_load($user_id); | |
$account_proxy = new \Drupal\Core\Session\AccountProxy(); | |
$account_proxy->setAccount($user); | |
$temp_store = new Drupal\Core\TempStore\PrivateTempStoreFactory( | |
\Drupal::service('keyvalue.expirable'), | |
\Drupal::service('lock'), | |
$account_proxy, | |
\Drupal::service('request_stack'), | |
604800 | |
); | |
$preview_converter = new \Drupal\node\ParamConverter\NodePreviewConverter($temp_store); | |
$preview = $preview_converter->convert($preview_id, NULL, NULL, []); | |
$preview_array = (array)$preview; | |
// The values of the node form are under a key called "*values". | |
dpm($preview_array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment