An API module that let you lock any resource to a user session.
It can be used to prevent concurrent access to the same resource, prevent editing conflict of entities, and so on, by associating an item identifier with a session identifier.
In it's most basic use, it provides:
- Basic CRUD operations:
- set/acquire
- get
- clear/release
- Views integration, by exposing the lock type, owner and time of the lock.
It also provides a unique entry point, hook_itemsessionlock_info, that provides far more, and let you define a lock 'type'. For each of these types, it will take care of creating for you:
- a menu callback to 'break' the locks
- a permission to break any locks of this type (used by the menu callback)
- an administrative view to see and manage locks of this type
- a cron task to delete old locks, along with a configuration variable to set how long locks should be kept
Drupal 7
Implementation consists in returning an array keyed by lock type, with a label, optionally disabling the auto-creation of any of the default components described above (menu, cron, view, permission).
/**
* Implements hook_itemsessionlock_info().
*/
function example_itemsessionlock_info() {
$locks = array();
$locks['my_type'] = array(
'label' => t('My type'),
// TRUE is the default, and does not need to be specified,
// given for reference only.
'view' => TRUE,
'permission' => TRUE,
'cron' => FALSE,
'menu' => TRUE,
);
$locks['another'] = array(
'label' => t('Another type'),
);
return $locks;
}
Drupal 8
Implementation consists in creating an annotated plugin, optionally overriding needed methods.
use Drupal\itemsessionlock\Plugin\ItemSessionLock\ItemSessionLockBase;
/**
* Provides a 'Node edit' lock.
*
* @ItemSessionLock(
* id = "itemsessionlock_example_node_edit",
* label = @Translation("Node")
* )
*/
class NodeEdit extends ItemSessionLockBase {
// Refer to parent class to see what methods are overridable.
}It also provides a handy itemsessionlock_item_ensure_lock() helper function that can be called to cover basic needs: it will try to acquire a lock, and on failure display a message to the user trying to access the resource, informing him/her someone else has locked the resource, with a link to break the lock if he/she has permission to do so, optionally redirecting before the message display.
It comes with an example module showing how to implement simple locking of user and node edit forms.
Note: This in an API module, and does nothing on its own. If you are looking for a ready to use module to prevent concurrent editing of nodes, you probably in the wrong place. See content_lock or conflict instead.
Project information
Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed.Maintenance fixes only
Considered feature-complete by its maintainers.- Project categories: Developer tools
- Created by bellesmanieres on , updated
Stable releases for this project are covered by the security advisory policy.
There are currently no supported stable releases.
