Skip to content

Get next incremental ID

Version v3

Initialising viewer…

You can apply this model as a recipe (Drupal 10.3 or later) to your own Drupal site:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Import recipe
composer require drupal-eca-recipe/eca_lib_0011

# Apply recipe with Drush (requires version 13 or later):
drush recipe ../recipes/eca_lib_0011

# Apply recipe without Drush:
cd web && php core/scripts/drupal recipe ../recipes/eca_lib_0011

# Rebuilding caches is optional, sometimes required:
drush cr

Purpose

This model increments a site-wide ID by 1 and returns that on screen. It keeps the value between requests in ECA's own persistent store.

That store is private to ECA. It is not Drupal's state service, so the counter is invisible to drush state:get and to any code that reads core state. For a counter this is the right trade-off, because the value is internal bookkeeping that nothing outside ECA needs to see. When you do need a value that other code can read, use the key value store actions with the collection state instead.

An "Acquire lock" action wraps the read and the write. Without it, two requests arriving at the same moment could read the same number and hand it out twice.

Dependencies

  • module
    • eca_base
    • eca_tamper
    • modeler_api

Used plugins

Events

Actions

Changelog

v1

Initial version

v2

Add an "Acquire lock" action to make sure it still works with concurrent users.

v3

Correct the documentation and summary, which claimed the counter is kept in Drupal's state service, when the persistent state plugins actually use ECA's own store. Fix the typos "sidewide" and "inbetween".