Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mirador #14

Merged
merged 39 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9d9737d
Add generated plugin manager files.
alxp Sep 9, 2022
58ce753
Support for Text Overlay plugin.
alxp Sep 9, 2022
49c4d55
WIP Add remote setting to config form
alxp Sep 15, 2022
10b1cb6
Add to settings.yml
alxp Sep 20, 2022
22f2ae5
Fix config form code error.
alxp Sep 21, 2022
c2e9e6d
WIP UPdate how Mirador is instantiated.
alxp Sep 22, 2022
2d68429
Support Mirador version 3.3
alxp Sep 23, 2022
50c17ab
Add core/drupal as a dependency in libraries.
alxp Oct 4, 2022
51ecb16
Move Mirador to /libraries folder.
alxp Oct 5, 2022
81992df
Put remote library back as default.
alxp Oct 5, 2022
f5911e8
Fix local javascript library definition.
alxp Oct 5, 2022
801b90c
WIP Refactor Mirador Plugin Manager.
alxp Oct 6, 2022
1578312
Fix library location form
alxp Oct 7, 2022
81e16cf
WIP Get plugin detection working.
alxp Oct 7, 2022
38c0539
WIP initial text overlay plugin file.
alxp Oct 11, 2022
f0fa3f4
WIP instantiate plugin in theme preprocess.
alxp Oct 13, 2022
687dd8d
WIP pass config into drupalSettings.
alxp Oct 14, 2022
e050675
Add enabled plugins to config form.
alxp Oct 21, 2022
4073538
WIP Set drupalSettings.
alxp Oct 21, 2022
6c68fce
WIP - get plugins and turn them ot objects.
alxp Oct 24, 2022
a0f0c72
Invoke plugins based on config.
alxp Oct 26, 2022
0d3c5e8
Add Image Tools plugin.
alxp Oct 27, 2022
b213d15
Update README and remove features.yml file.
alxp Oct 28, 2022
f7d40c3
Add update hook to set default config.
alxp Nov 16, 2022
5bbdb5c
CHange default mirador library CDN location.
alxp Nov 17, 2022
d5703e7
Don't load fallback Mirador application in alter hook.
alxp Nov 21, 2022
7010f58
Add plugin section to README.
alxp Nov 28, 2022
5c30da2
Add more documentation around custom plugins to README.
alxp Jan 4, 2023
ce72e5c
update-mirador-pat --- wild attempt at documentation, mainly focusing…
patdunlavey Jan 4, 2023
158d7a6
Make the remote library location non-editable in the UI per PR discus…
alxp Jan 5, 2023
701c45e
Merge pull request #16 from patdunlavey/update-mirador-pat
alxp Jan 6, 2023
05f4a4f
Further README additions.
alxp Jan 6, 2023
ee4d95d
Remove unused default js library location.
alxp Jan 6, 2023
e4d5f9b
WIP remove custom remote option.
alxp Jan 9, 2023
eb9be23
Remove remote library option.
alxp Jan 10, 2023
98c2bb0
Remove reference to library location setting.
alxp Jan 10, 2023
eb07272
Update src/Form/MiradorConfigForm.php
alxp Jan 10, 2023
02fc284
Update islandora_mirador.module with formatting suggestion
alxp Jan 10, 2023
d021305
Remove extra newline.
alxp Jan 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

## Introduction

This module provides Drupal integration for the [Mirador](https://projectmirador.org) image viewer.
This is a Drupal module that wraps around the Mirador image viewer.
It does not strictly require Islandora, however it depends on an [IIIF Manifest](https://iiif.io/api/presentation/2.0/),
Islandora generates these manifests but they can also come from
third-party sources.

## Installation

Expand All @@ -21,10 +24,16 @@ $ drush en islandora_mirador

### Upgrading from Islandora Defaults

This module was formerly distributed with Islandora Defaults. If you are upgrading
This module was formerly distributed with Islandora Defaults. If you are upgrading
you may need to clear Drupal's cache and re-start your web server to resolve
a Plugin Not Found error.

### Local library

The module can use either an instance of Mirador Integration hosted
on the web or deployed locally. If you have a local build, put it in
your webroot at libraries/mirador/dist/main.js.

## Usage

The module provides a view mode that can be selected as a display hint when editing an Islandora Repository Item object.
Expand All @@ -37,6 +46,12 @@ This module also provides a Block that can be included in custom displays.

The configuration page is located at /admin/config/media/mirador.

YOu can select if the library is deployed locally or set the remote
library's location.

You can also enable particular plugins. You need to know if the
plugins are included in the particular build of Mirador Integration.

You can set the URL pattern to retrieve the IIIF manifest for a piece of content.

## Documentation
Expand All @@ -49,10 +64,10 @@ Having problems? Solved a problem? Join the Islandora [communication channels](h

* [Islandora Mailing List (Google Group)](https://groups.google.com/g/islandora)


* If you would like to contribute or have questions, please get involved by attending our weekly [Tech Call](https://github.com/Islandora/islandora-community/wiki/Weekly-Open-Tech-Call), held virtually via Zoom **every Wednesday** at [**1:00pm Eastern Time US**](https://dateful.com/convert/est-edt-eastern-time?t=13). Anyone is welcome to join and ask questions! The Zoom link can be found in the meeting minutes [here](https://github.com/Islandora/islandora-community/wiki/Weekly-Open-Tech-Call).

If you would like to contribute code to the project, you need to be covered by an Islandora Foundation [Contributor License Agreement](https://github.com/Islandora/islandora-community/wiki/Onboarding-Checklist#contributor-license-agreements) or [Corporate Contributor License Agreement](https://github.com/Islandora/islandora-community/wiki/Onboarding-Checklist#contributor-license-agreements). Please see the [Contributor License Agreements](https://github.com/Islandora/islandora-community/wiki/Contributor-License-Agreements) page on the islandora-community wiki for more information.
## License

[GPLv2](http://www.gnu.org/licenses/gpl-2.0.txt)

3 changes: 3 additions & 0 deletions config/install/islandora_mirador.settings.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
mirador_library_use_remote: 'remote'
mirador_library_location: 'https://roblib.github.io/mirador-integration-islandora/islandora-mirador-0.1.0.js'
alxp marked this conversation as resolved.
Show resolved Hide resolved
mirador_enabled_plugins: { }
iiif_manifest_url: 'http://localhost:8000/node/[node:nid]/manifest'
12 changes: 12 additions & 0 deletions config/schema/islandora_mirador.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ islandora_mirador.settings:
type: config_object
label: 'Mirador Settings'
mapping:
mirador_library_use_remote:
type: string
label: 'Mirador library use remote'
mirador_library_location:
type: string
label: 'Mirador library remote location'
mirador_enabled_plugins:
type: sequence
label: 'Enabled Plugins'
sequence:
type: string
label: 'Plugin'
iiif_manifest_url:
type: string
label: 'URL pattern for IIIF manifest view'
1 change: 0 additions & 1 deletion islandora_mirador.features.yml

This file was deleted.

13 changes: 13 additions & 0 deletions islandora_mirador.install
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ function islandora_mirador_update_8001() {
_get_or_create_tag();
}

/**
* Set a default config value for mirador_library_use_remote
* @return void
*/
function islandora_mirador_update_20001() {
$config = \Drupal::configFactory()->getEditable('islandora_mirador.settings');

$config->set('mirador_library_use_remote', 'remote');
$config->set('mirador_library_location', 'https://roblib.github.io/mirador-integration-islandora/islandora-mirador-0.1.0.js');

$config->save();
}

/**
* Looks up or creates Mirador term.
*/
Expand Down
5 changes: 3 additions & 2 deletions islandora_mirador.libraries.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
mirador:
version: 3.0.0-rc5
version: 3.3.0
remote: https://projectmirador.org
license:
name: Apache license
url: https://github.com/ProjectMirador/mirador/blob/master/LICENSE
gpl-compatible: true
js:
https://cdn.jsdelivr.net/npm/mirador@3.0.0-rc.5/dist/mirador.min.js: { type: external, minified: true}
https://cdn.jsdelivr.net/npm/mirador@3.3.0/dist/mirador.min.js: { type: external, minified: true}
viewer:
version: 1.x
js:
Expand All @@ -15,5 +15,6 @@ viewer:
theme:
css/mirador.css: {}
dependencies:
- core/drupal
- core/drupalSettings
- islandora_mirador/mirador
49 changes: 49 additions & 0 deletions islandora_mirador.module
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/

use Drupal\Component\Utility\Html;
use Drupal\Core\Config\ImmutableConfig;

use Drupal\islandora_mirador\IslandoraMiradorPluginPluginBase;
use Drupal\islandora_mirador\IslandoraMiradorPluginInterface;

/**
* Implements hook_theme().
Expand All @@ -28,4 +32,49 @@ function islandora_mirador_theme() {
function template_preprocess_mirador(&$variables) {
$variables['mirador_view_id'] = Html::getUniqueId($variables['mirador_view_id']);
$variables['#attached']['drupalSettings']['mirador_view_id'] = $variables['mirador_view_id'];

/**
* @var \Drupal\islandora_mirador\IslandoraMiradorPluginManager
*/
$mirador_plugin_manager = \Drupal::service('plugin.manager.islandora_mirador');

/**
* @var \Drupal\Core\Config\ImmutableConfig
*/
$config = Drupal::service('config.factory')->get('islandora_mirador.settings');

$mirador_plugins = $mirador_plugin_manager->getDefinitions();
$enabled_plugins = $config->get('mirador_enabled_plugins');
$variables['#attached']['drupalSettings']['mirador_enabled_plugins'] = array_filter(array_values($enabled_plugins));

$window_config = [];
foreach ($mirador_plugins as $plugin_id => $plugin_definition) {
if ($enabled_plugins[$plugin_id]) {
$plugin_instance = $mirador_plugin_manager->createInstance($plugin_id);
/**
* @var Drupal\islandora_mirador\IslandoraMiradorPluginInterface
*/
$plugin_instance->windowConfigAlter($window_config);
}
}
$variables['#attached']['drupalSettings']['mirador_window_settings'] = $window_config;
}

function islandora_mirador_library_info_alter(&$libraries, $extension) {
alxp marked this conversation as resolved.
Show resolved Hide resolved
if ($extension == 'islandora_mirador') {

$config = \Drupal::service('config.factory')->get('islandora_mirador.settings');
if ($config->get('mirador_library_use_remote') =='remote') {
$libraries['mirador']['js'] = [];
$libraries['mirador']['js'][$config->get('mirador_library_location')] = [
'type' => 'external',
'minified' => TRUE,
];
}
else {
unset($libraries['mirador']['remote']);
unset($libraries['mirador']['license']);
$libraries['mirador']['js']['/libraries/mirador/dist/main.js'] = [];
}
}
}
4 changes: 4 additions & 0 deletions islandora_mirador.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
services:
plugin.manager.islandora_mirador:
class: Drupal\islandora_mirador\IslandoraMiradorPluginManager
parent: default_plugin_manager
24 changes: 14 additions & 10 deletions js/mirador_viewer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*jslint browser: true*/
/*global Mirador, Drupal*/
/*global Mirador, textOverlayPlugin, Drupal*/
/**
* @file
* Displays Mirador viewer.
Expand All @@ -20,20 +20,24 @@

function init(context,settings){
if (!initialized){
initialized = true;
var miradorInstance = Mirador.viewer({
"id": base,
"manifests": {
[settings.iiif_manifest_url]: {provider: "Islandora"}
},
"windows": [
initialized = true;

/*
Mirador
*/
var miradorInstance = Mirador.viewer({
"id": base,
"manifests": {
[settings.iiif_manifest_url]: {provider: "Islandora"}
},
"window": settings.mirador_window_settings,
"windows": [
{
"manifestId": settings.iiif_manifest_url,
"thumbnailNavigationPosition": 'far-bottom'
}
]
})

}, window.miradorPlugins);
}
}
Drupal.Mirador = Drupal.Mirador || {};
Expand Down
39 changes: 39 additions & 0 deletions src/Annotation/IslandoraMiradorPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Drupal\islandora_mirador\Annotation;

use Drupal\Component\Annotation\Plugin;

/**
* Defines islandora_mirador annotation object.
*
* @Annotation
*/
class IslandoraMiradorPlugin extends Plugin {

/**
* The plugin ID.
*
* @var string
*/
public $id;

/**
* The human-readable name of the plugin.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $title;

/**
* The description of the plugin.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $description;

}
74 changes: 73 additions & 1 deletion src/Form/MiradorConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\islandora_mirador\Annotation\IslandoraMiradorPlugin;
use Drupal\islandora_mirador\IslandoraMiradorPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Mirador Settings Form.
*/
class MiradorConfigForm extends ConfigFormBase {
/**
* @var \Drupal\islandora_mirador\IslandoraMiradorPluginManager
*/
protected $miradorPluginManager;

/**
* {@inheritdoc}
Expand All @@ -23,6 +30,44 @@ public function getFormId() {
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this->config('islandora_mirador.settings');
$form['mirador_library_fieldset'] = [
'#type' => 'fieldset',
'#title' => $this->t('Mirador library location'),
];
$form['mirador_library_fieldset']['mirador_library_use_remote'] = [
'#type' => 'radios',
'#options' => [
'local'=> $this->t('Local library placed in /libraries inside your webroot.'),
'remote' => $this->t('Remote (e.g. on a CDN)'),
],
'#default_value' => $config->get('mirador_library_use_remote'),
];

$form['mirador_library_fieldset']['mirador_library_location'] = [
'#type' => 'textfield',
'#title' => $this->t('Remote Mirador library location'),
'#description' => $this->t('Remote URL of compiled Mirador library. It must be minified and be a single file.'),
'#default_value' => $config->get('mirador_library_location'),
'#states' => [
// Show this field only if the 'remote' option is selected above.
'enabled' => [
':input[name="mirador_library_use_remote"]' => [
'value' => 'remote',
],
],
],
];
alxp marked this conversation as resolved.
Show resolved Hide resolved
$plugins = [];
foreach ($this->miradorPluginManager->getDefinitions() as $plugin_key => $plugin_definition) {
$plugins[$plugin_key] = $plugin_definition['label'];
}
$form['mirador_library_fieldset']['mirador_enabled_plugins'] = [
'#title' => $this->t('Enabled Plugins'),
'#description' => $this->t('Which plugins to enable. The plugins must be compiled in to the application. See the documentation for instructions.'),
'#type' => 'checkboxes',
'#options' => $plugins,
'#default_value' => $config->get('mirador_enabled_plugins'),
];
$form['iiif_manifest_url_fieldset'] = [
'#type' => 'fieldset',
'#title' => $this->t('IIIF Manifest URL'),
Expand Down Expand Up @@ -51,6 +96,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('islandora_mirador.settings');
$config->set('mirador_library_use_remote', $form_state->getValue('mirador_library_use_remote'));
$config->set('mirador_library_location', $form_state->getValue('mirador_library_location'));
$config->set('mirador_enabled_plugins', $form_state->getValue('mirador_enabled_plugins'));
$config->set('iiif_manifest_url', $form_state->getValue('iiif_manifest_url'));
$config->save();
parent::submitForm($form, $form_state);
Expand All @@ -65,4 +113,28 @@ protected function getEditableConfigNames() {
];
}


alxp marked this conversation as resolved.
Show resolved Hide resolved
/**
* Constructs the Mirador config form.
*
* @param ConfigFactoryInterface $config_factory
* The configuration factory.
* @param IslandoraMiradorPluginManager $mirador_plugin_manager
* The Mirador Plugin Manager interface.
*/
public function __construct(ConfigFactoryInterface $config_factory, IslandoraMiradorPluginManager $mirador_plugin_manager) {
parent::__construct($config_factory);
$this->miradorPluginManager = $mirador_plugin_manager;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('plugin.manager.islandora_mirador')
);
}

}
Loading