pre-book entity IDs when saving new ones

Created on 24 January 2012, over 13 years ago
Updated 24 June 2023, about 2 years ago

It's a well-known problem that you can't use the node:nid token in a node's automatic title ( #176468: The token "[nid]" doesn't work. ), and more generally, anything that you want to do with an entity that you might want to do to a brand new entity and which needs the ID, won't work.

So here's my idea. What if we 'pre-booked' the ID, by entering a mostly empty row in the entity's table before all the save hooks are fired?

Here's pseudocode to illustrate this:

function entity_save($entity) {
 // Pre-book a row.
 $new_row = drupal_write_record(entity table, array());
 
  $entity->id = $new_row->id;

  // Fire the rest of the normal save procedure and fire the usual hooks.
}

We'd presumably need a different way of knowing it's a new entity rather than an update as most hooks will use the presence / absence of the id key. But apart from that, could this work?

Feature request
Status

Postponed: needs info

Version

9.5

Component
Entity 

Last updated 1 day ago

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024