drupal-eca-recipe / eca_lib_0011
Increments a site-wide counter and returns it, keeping the value between requests in ECA's own persistent store rather than in Drupal's state service. An "Acquire lock" action guards the read and the write so that two concurrent requests cannot receive the same number.
Package info
gitlab.lakedrops.com/drupal/recipes/eca_lib_0011
Type:drupal-recipe
pkg:composer/drupal-eca-recipe/eca_lib_0011
Requires
- drupal/eca: *
- drupal/eca_tamper: *
- drupal/modeler_api: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
ID: eca_lib_0011
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.
Installation
## 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