Skip to content

Instantly share code, notes, and snippets.

@ericjgruber
Last active July 24, 2017 21:08
Show Gist options
  • Save ericjgruber/c57b8315f5ed58a8957ed303509b75b0 to your computer and use it in GitHub Desktop.
Save ericjgruber/c57b8315f5ed58a8957ed303509b75b0 to your computer and use it in GitHub Desktop.
Get a UUID in Drupal 8
/** @var \Drupal\user\Entity\User $user */
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
$uuid = $user->uuid();
@ericjgruber
Copy link
Author

To reveal the uuid in a JavaScript object, add this to the .theme file in the HOOK_preprocess_page(&$variables) function:

$variables['#attached']['drupalSettings']['uuid'] = $uuid;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment