|
|
2 days ago | |
|---|---|---|
| config | 2 days ago | |
| js | 2 days ago | |
| src | 2 days ago | |
| LICENCE | 2 days ago | |
| README.md | 2 days ago | |
| composer.json | 2 years ago | |
| islandora_altmetric.info.yml | 2 days ago | |
| islandora_altmetric.libraries.yml | 2 days ago | |
| islandora_altmetric.links.menu.yml | 2 days ago | |
| islandora_altmetric.module | 2 years ago | |
| islandora_altmetric.routing.yml | 2 days ago | |
README.md
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.2 or later in the 10.x series, or Drupal 11.
- 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 Altmetric embed service.
- 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 is under Configuration > System.
Configuration values
The configuration object is islandora_altmetric.settings.
| Key | Purpose | Fallback |
|---|---|---|
doi_field |
Machine name of the DOI field | field_doi when unset or empty |
style |
Badge type passed to the embed element | 4 when unset or unrecognized |
Settings are shared by all block instances. New installations receive default configuration from config/install/islandora_altmetric.settings.yml. Existing installations retain their saved configuration; runtime fallbacks also cover missing settings. Inspect saved settings with:
drush config:get islandora_altmetric.settings
How it works
The block obtains the node from the current route, checks that the configured field exists and is viewable, and reads its first value. If no DOI is available, it renders no badge. Otherwise a Drupal html_tag render array produces the embed element with escaped attributes. The external library uses Altmetric's stable HTTPS entry point, and a Drupal behavior requests a rescan for newly inserted AJAX/BigPipe badges.
Caching varies by route and content language, with node and configuration cache tags and field access cache metadata. Changing a DOI or the badge settings invalidates cached output, including previously empty blocks. The score itself is fetched by the browser, not cached by Drupal.
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/Plugin/Block/IslandoraAltmetricBlock.php |
Block plugin and badge rendering |
js/doi_embed.js |
AJAX/BigPipe badge refresh behavior |
config/schema/islandora_altmetric.schema.yml |
Configuration schema |
config/install/islandora_altmetric.settings.yml |
Defaults for new installations |
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
embed.altmetric.comand other hosts listed in the vendor documentation. - Configuration menu missing: use the direct settings URL.
Upgrading an existing installation
Replace the old module directory (do not merely overlay files, because the duplicate AltmetricSettingsForm.php has been removed). Keep the same module machine name. No uninstall or reinstall is necessary. The existing settings object, route, and block plugin ID are unchanged.
drush cr
drush config:get islandora_altmetric.settings
Review and save settings if needed. Export configuration using drush cex if this site uses configuration management. If a manually edited configuration contains a numeric style, resaving the form stores it as a string.
Maintenance and security
- The settings form initializes the parent configuration services, including the typed configuration manager required by Drupal 11.
- The vendor script is external and excluded from Drupal preprocessing. Do not pin its generated asset filenames.
- Review third-party script privacy and CSP requirements. See Altmetric embed documentation for current allowed hosts and script initialization guidance.
- The module expects a DOI in a plain string field; it does not verify DOI registration or query Altmetric server-side.
Manual verification after deployment
- Open the settings page, save each style, and confirm that existing settings persist.
- Visit two nodes with different DOIs, a node without a DOI, and a non-node route. Confirm the badge appears only as appropriate and is not reused between nodes.
- Add a DOI to a previously empty node, change a DOI, and change the badge style without clearing caches; verify the new output appears.
- Check field access with a restricted user if field access controls are installed.
- Confirm the vendor script loads once, including with aggregation enabled, and test AJAX/BigPipe rendering and any CSP rules.
PHP and JavaScript syntax and YAML parsing were checked. No live Drupal installation is included; the above integration checks remain to be performed.