The registry is a key-value store which loads on each request and contains information about the request and other context. It allows modules to set and request information along the execution chain.

It was inspired by the CMI and WSCCI initiatives for Drupal 8, but attempts to provide a useful feature to Drupal 6. The registry is only for aggregating information about the current request, and is not used for storing information across requests (for this, use Drupal's variable functions, or consider the Object Cache module).

Some things you might be able to do with the Registry

  • React to request information
  • Access node information outside the node object (for example, in a block)
  • Set a context for other modules to react to
  • Avoid global $var
  • Never call arg(1) again!

Features

Registry currently loads the following:

  • Basic request information (args, path)
  • The current node, if on a node path
  • The current user

API

Functional wrappers are provided to work with the registry object. Using the wrappers ensures that the registry functions correctly. The two important ones are the get and set functions, which work in a similar manner to Drupal's variable get and set functions.

Set a registry value
This function expects a string key, however the value can be anything.

<?php
registry_set
($key, $value, $protected = FALSE);
?>

Set a registry value using a callback

<?php
registry_set_callback
($key, $callback, $args = NULL, $protected = FALSE);
?>

Setting by reference is generally discouraged, however you can set directly using a more verbose method, which also also allows passing in objects by reference, for example.

<?php
$registry
= &registry_invoke();
$registry->$key['#value'] =& $value;
?>

Access a registry value

<?php
registry_get
($key);
?>

Delete a registry value

<?php
registry_delete
($key);
?>

Downloads

Version Downloads Date Links
6.x-1.0-beta1 tar.gz (11.15 KB) | zip (15.74 KB) 2012-Mar-22 Notes

Project Information


Maintainers for Registry

  • xtfer - 23 commits
    last: 5 weeks ago, first: 50 weeks ago

Issues for Registry

To avoid duplicates, please search before submitting a new issue.
All issues
Bug reports
nobody click here