Entity keys

The entity API defines a set of keys that are consistent across all entity types and by which common entity information can be retrieved. Since not all entity types need to have the same fields for storing that data, there is a mapping that can be done in the annotation for these:

 *   entity_keys = { *     "id" = "nid", *     "revision" = "vid", *     "bundle" = "type", *     "label" = "title", *     "langcode" = "langcode", *     "uuid" = "uuid", *     "status" = "status", *     "uid" = "uid", *   },

The Node entity type has a relatively comprehensive example of entity keys. As you can see, the unique identifier field for Nodes has always been nid. However, the common identifier for entities across the system is id. So, a mapping here helps facilitate that.

Get Drupal 8 Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.