- The `islandora_object` content type with a plain string field containing a DOI.
- Browser access to the external Altmetric script hosts.
- Browser access to the Altmetric embed service.
- Permission to administer site configuration and place blocks.
## Installation
@ -30,7 +30,7 @@ The Composer package name is `roblib/islandora-altmetric`. The module is license
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 references the Islandora Citations configuration overview; use the direct settings URL if that parent menu is unavailable.
The settings route requires `administer site configuration`. The menu link is under Configuration > System.
### Configuration values
@ -38,10 +38,10 @@ 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 |
| `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. There is no shipped default configuration file. Inspect saved settings with:
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:
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.
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
@ -61,29 +63,43 @@ The block obtains the node from the current route, reads the first value of the
| `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 `badge.altmetric.com` and `d1bxh8uas1mnw7.cloudfront.net`.
- **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.
## Maintenance notes
## 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.
The following existing implementation details warrant review before production deployment. They have been documented rather than changed in this documentation-only revision:
## Manual verification after deployment
- Two similarly named settings form classes exist. Only the singular `AltmetricSettingForm` is routed by this module.
- Both forms supply their own constructor without calling the parent constructor. Compatibility with the installed Drupal version's `ConfigFormBase` services should be tested.
- The schema contains placeholder `example` entries rather than definitions for `doi_field` and `style`.
- 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 `#markup` may 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.
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.
No live Drupal installation or automated module tests are included in the supplied archive.
PHP and JavaScript syntax and YAML parsing were checked. No live Drupal installation is included; the above integration checks remain to be performed.
public function __construct(EntityFieldManagerInterface $entity_field_manager) {
public function __construct(ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config_manager, EntityFieldManagerInterface $entity_field_manager) {