5.6 KiB
Islandora Altmetric
A custom Drupal module that displays an Altmetric badge on repository object pages using a DOI stored in a node field. Badge rendering is delegated to external Altmetric JavaScript; the module does not retrieve or store metric scores itself.
Requirements
- Drupal 10 or 11 (as declared in the module metadata).
- Islandora 2.x (Composer requirement:
drupal/islandora: ^2.0). - The
islandora_objectcontent type with a plain string field containing a DOI. - Browser access to the external Altmetric script hosts.
- Permission to administer site configuration and place blocks.
Installation
Copy the module directory into the site's custom modules directory, for example web/modules/custom/islandora_altmetric, then enable it from Extend or with Drush from the Drupal project directory:
drush en islandora_altmetric -y
drush cr
The Composer package name is roblib/islandora-altmetric. The module is licensed under GPL-2.0-or-later, as declared in composer.json.
Configuration
- Visit
/admin/config/system/altmetric-settings. - Select DOI Field. The form lists fields on
islandora_objectwhose field type isstringand whose machine name begins withfield. - Select Badge Style: Default (
4), Donut (donut), Medium Donut (medium-donut) or Large Donut (large-donut). - Save configuration.
- Go to Structure > Block layout (
/admin/structure/block), place the Islandora Altmetric block in the desired theme region, and configure visibility as appropriate for repository object pages. - Visit a node with a DOI and verify that the badge appears.
The settings route requires administer site configuration. The menu link references the Islandora Citations configuration overview; use the direct settings URL if that parent menu is unavailable.
Configuration values
The configuration object is islandora_altmetric.settings.
| Key | Purpose | Fallback |
|---|---|---|
doi_field |
Machine name of the DOI field | field_doi when null |
style |
Badge type passed to the embed element | No explicit fallback |
Settings are shared by all block instances. There is no shipped default configuration file. Inspect saved settings with:
drush config:get islandora_altmetric.settings
How it works
The block obtains the node from the current route, reads the first value of the configured DOI field, and returns an empty render array if the node or DOI is missing. Otherwise it generates an altmetric-embed element with data-doi, data-badge-type, and a right-positioned popover. The block includes an external script reference and attaches a local Drupal library, which loads another external Altmetric script from CloudFront. The populated block sets its render cache maximum age to zero.
File layout
| File | Responsibility |
|---|---|
islandora_altmetric.info.yml |
Module metadata and dependencies |
islandora_altmetric.routing.yml |
Settings form route |
islandora_altmetric.links.menu.yml |
Administration menu link |
islandora_altmetric.libraries.yml |
JavaScript library definition |
islandora_altmetric.module |
Module hook file (currently no hooks) |
src/Form/AltmetricSettingForm.php |
Active site-wide settings form |
src/Form/AltmetricSettingsForm.php |
Alternate form, not referenced by the supplied routing file |
src/Plugin/Block/IslandoraAltmetricBlock.php |
Block plugin and badge rendering |
js/doi_embed.js |
External script loader |
config/schema/islandora_altmetric.schema.yml |
Existing configuration schema |
composer.json |
Package metadata and dependency declaration |
Troubleshooting
- No badge: verify the block is placed and visible, the current route has a node, and the configured field contains a valid DOI. A DOI does not guarantee that Altmetric has a badge or tracked activity for it.
- DOI field missing from settings: verify the content type, field type and machine name against the selection criteria above.
- External script not loading: inspect the browser console and network panel for content security policy restrictions, blockers, or failed requests to
badge.altmetric.comandd1bxh8uas1mnw7.cloudfront.net. - Configuration menu missing: use the direct settings URL.
Maintenance notes
The following existing implementation details warrant review before production deployment. They have been documented rather than changed in this documentation-only revision:
- Two similarly named settings form classes exist. Only the singular
AltmetricSettingFormis routed by this module. - Both forms supply their own constructor without calling the parent constructor. Compatibility with the installed Drupal version's
ConfigFormBaseservices should be tested. - The schema contains placeholder
exampleentries rather than definitions fordoi_fieldandstyle. - The DOI and style are interpolated directly into HTML attributes. Review attribute escaping and validation, and prefer a structured render array. The script tag in
#markupmay also be filtered by Drupal. - There are two external script-loading paths and a redundant initial render-array assignment. Review whether both loading paths are needed and whether the pinned CloudFront URL remains supported.
- Review cache metadata for empty block returns and consider appropriate node, route and configuration dependencies instead of disabling caching for populated badges.
- Third-party scripts execute in the visitor's browser; review privacy and content security policy requirements.
No live Drupal installation or automated module tests are included in the supplied archive.