8

I am aware that the question is (almost) a duplicate of the following question #21991, which has been posted back in 2012. But that question is NOT related to Drupal 8, where UUID is in core.

References:

The Drupal 8 Core Module Documentation does not list UUID.

I wonder if I could leverage Drupal 8's core UUID module to migrate and map relational data imported from a different environment, which has unique keys generated by Firebase.

Update:

It has been kindly pointed out that UUID is not a module.

It seems to make UUID records per default for entities (aka nodes) and apparently can be used to map entity references.

Can I make use of this when I introduce external data, that already has unique IDs? So I have the "node" IDs and can map with the UUIDs?

Update based on further comments:

The goal is to use UUID with entities and the REST module. Respectively, it seems sensible to do so when importing external relational data, that already has unique IDs.

I just try to understand how UUID works, what it can do and what not, how I can generate and validate UUID's, what I need to be aware of, if I introduce external ID's.

  • Pierre, thank you for your constructive comments! I rephrased my question. – Stefan Apr 4 '15 at 6:49
  • There is no UUID module, just the API. – Berdir Apr 4 '15 at 7:09
  • @Berdir, Thank you. OK. Let me rephrase the question: How to use the UUID API provided by Drupal 8 core? It does make UUID records per default for entities (aka nodes) and apparently can be used to map entity references. – Stefan Apr 4 '15 at 7:13
8

I assume what you want to know is how to generate a UUID in Drupal 8, because there's really not much else that you can do ;)

Entities all have an UUID automatically, so if you store your data as a config or content entity, you just have to define the uuid entity key.

To generate a UUID yourself, you need the uuid service:

$uuid = \Drupal::service('uuid');
$uuid->generate();
$uuid->isValid($uuid_to_validate);
  • Thank you. I understand so far, that they are generated automatically. So you suggest that I have to introduce the external UUID logic via the service you mentioned? But that would be for generation. Can I also save an entity with a given UUID? – Stefan Apr 4 '15 at 7:23
  • Sorry, I haven't tried it yet. That's why I was originally asking for a documentation, so I can do some research. – Stefan Apr 4 '15 at 7:24
  • I'm not sure I understand. Note that I'm talking about a (Symfony) Dependency injection service, not a web service. Yes, you can save entities with your own UUID if you already have one, just pass it to YourEntity::create() as an initial value. – Berdir Apr 4 '15 at 7:27
  • Ok thank you. Do you know where I can get more information about this, besides the API? Because it's somewhat difficult to figure out the whole picture just looking at the API. – Stefan Apr 4 '15 at 7:33
  • Not sure which picture you mean as it is still not clear to me what you are trying to do. There really is nothing more to say about the UUID component/service itself, it does nothing but generate and validate UUID's. If that does not answer your question, then maybe you asked the wrong question :) Try to ask exactly what you are trying to achieve, possibly as a new question. Because it might be that your question isn't so much about UUID as it is about how entity or maybe the REST module are using UUID's. Also, hi fellow Swiss person :) – Berdir Apr 4 '15 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.