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 \Drupal\polling\UrlGenerator::instance()
:
// Currently this only works for nodes.
$url = \Drupal\polling\UrlGenerator::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
Project information
- Module categories: Developer Tools
- 145 sites report using this module
- Created by torotil on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
fix inital polling interval