Polling

Categories

Component ID

2650240

Component name

Polling

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

530

Component created

Component changed

Component body

This is a module for developers. It does nothing on its own except making development of other modules easer.

The polling module provides a common way to poll data on a drupal site. The module takes care of the actual XHR requests and the necessary headers to facilitate effective caching for those resources.

How to poll resources

To poll a resource you have to register a callback via JavaScript. The callback is called whenever the polling module gets data for this resource. Usually it interprets the result and modifies the content of the website accordingly.

First you have to get the polling-URL. This is done on the server-side in PHP by using the DrupalpollingUrlGenerator::instance():

// Currently this only works for nodes.
$url = DrupalpollingUrlGenerator::instance()->entityUrl('node', 57);
$settings['my_module']['pollingUrl'] = $url;
drupal_add_js($settings, 'setting');

Then you can register your callback via a JavaScript behavior:

Drupal.behviors.my_module = {
  attach: function(context, settings) {
    callback = function(data) {
      alert(data.my_module.hello_world);
    }
    Drupal.behaviors.polling.registerUrl(settings.my_module.pollingUrl, 'my_module', callback);
  },
};

Add the moment there is two kinds of resources:

  • Entities (currently only nodes are supported).
  • Global (site-wide) data

How to add your data to a ressource

TBD

Modules using this module

  • pgbar - a progress bar for online actions.
  • recent_supporters - a list of recent-supporters for online actions