# 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_object` content 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: ```sh 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 1. Visit `/admin/config/system/altmetric-settings`. 2. Select **DOI Field**. The form lists fields on `islandora_object` whose field type is `string` and whose machine name begins with `field`. 3. Select **Badge Style**: Default (`4`), Donut (`donut`), Medium Donut (`medium-donut`) or Large Donut (`large-donut`). 4. Save configuration. 5. 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. 6. 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: ```sh 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.com` and 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. ```sh 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](https://docs.altmetric.com/badges/getting-started/) 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 1. Open the settings page, save each style, and confirm that existing settings persist. 2. 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. 3. Add a DOI to a previously empty node, change a DOI, and change the badge style without clearing caches; verify the new output appears. 4. Check field access with a restricted user if field access controls are installed. 5. 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.