luzmo_viewer
This module intend to add a custom field that allow users to display Luzmo dashboard ID using javascript embed API.
Features
The module allow content editor to embed dashboard.
Dashboard can be displayed using integration key and token but site builder can also use embed tokens to display the dashboards.
Post-Installation
Module settings
Once installed go to /admin/config/system/luzmo-settings and change settings.
You'll need to fill:
- authkey: with your Luzmo API key
- authtoken: with your token API key
- luzmo.js location: define the location of the Luzmo embed library .js file. Default use remote version of the library.
- Luzmo App Server: you can change here the url of the Luzmo app server, default is https://app.luzmo.com/
The Account settings for logged-in or anonymous users allow you define user information required for authorisation.
It is only required if you need to request an authorisation.
Luzmo configuration
Create an integration on Luzmo ( https://app.luzmo.com/integrations ).
Select the dashboard you want to be embedded on drupal.
At the end of the process get the key & token.
You can still add dashboard later, just do not re-generate key and token.
Field creation
After that, create a Luzmo viewer field on your entity.
There is no settings for the form widget.
In the display you can set if formatter need to request an authorisation.
Additional Requirements
The module require Luzmo embed web component. You can use it remotely or localy https://socket.dev/npm/package/@luzmo/embed
If you decide to request an authorization , please make sure that users/suborganisations will have permissions to access the data.
Additional Information
Field cache
When authorisation is request, field use a per user cache with the max-age set to the authorisation inactivity interval time.
How can I alter cache?
Use drupal preprocess to alter cache contexts, ex:
/**
* Implements hook_preprocess_HOOK().
*/
function hook_preprocess_field(&$variables) {
// conditions
foreach ($variables["items"] as &$items) {
$items['content']["#cache"]["contexts"][] = 'cookies:luzmoFilters';
}
}
I want to alter authorisation
Module implement a custom hook that allow you alter the authorisation before it's requested.
Example, it can allow to pre-fill dashboard filters.
Module implemant a hook: hook_luzmo_viewer_dashboard_javascript_authorisation_alter that can be called in module or theme.
Example:
I want to alter dashboard filters
/**
* Alter authorisation settings to add filters based on cookie.
*
* {@see hook_luzmo_viewer_dashboard_javascript_authorisation_alter}.
*/
function hook_luzmo_viewer_dashboard_javascript_authorisation_alter(&$authorizationSettings, $dashboard_id) {
$luzmoFilters = Drupal::request()->cookies->get('luzmoFilters');
if (!empty($luzmoFilters)) {
$luzmoFilters = json_decode($luzmoFilters, TRUE);
foreach ($luzmoFilters as $filter_dashboard_id => $filters) {
if ($filter_dashboard_id == $dashboard_id) {
$authorizationSettings['filters'] = $filters;
}
}
}
}