You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.2 KiB
67 lines
2.2 KiB
<?php |
|
|
|
/** |
|
* @file |
|
* Runtime integration for Islandora Mirador Annotations. |
|
*/ |
|
|
|
use Drupal\Core\Asset\AttachedAssetsInterface; |
|
use Drupal\Core\Url; |
|
|
|
/** |
|
* Implements hook_library_info_alter(). |
|
* |
|
* The base module remains untouched. We replace only its viewer dependency on |
|
* the stock Mirador bundle with our compatible bundle containing the same |
|
* Islandora plugins plus Mirador Annotation Editor. |
|
*/ |
|
function islandora_mirador_annotations_library_info_alter(array &$libraries, $extension) { |
|
if ($extension !== 'islandora_mirador' || empty($libraries['viewer']['dependencies'])) { |
|
return; |
|
} |
|
|
|
$libraries['viewer']['dependencies'] = array_values(array_filter( |
|
$libraries['viewer']['dependencies'], |
|
static fn ($dependency) => $dependency !== 'islandora_mirador/mirador' |
|
)); |
|
|
|
if (!in_array('islandora_mirador_annotations/annotated_mirador', $libraries['viewer']['dependencies'], TRUE)) { |
|
$libraries['viewer']['dependencies'][] = 'islandora_mirador_annotations/annotated_mirador'; |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_js_settings_alter(). |
|
*/ |
|
function islandora_mirador_annotations_js_settings_alter(array &$settings, AttachedAssetsInterface $assets) { |
|
if (empty($settings['mirador']['viewers']) || !is_array($settings['mirador']['viewers'])) { |
|
return; |
|
} |
|
|
|
$account = \Drupal::currentUser(); |
|
if (!$account->hasPermission('view mirador annotations')) { |
|
return; |
|
} |
|
|
|
$endpoint = Url::fromRoute('islandora_mirador_annotations.collection', [], ['absolute' => TRUE])->toString(); |
|
$can_manage = $account->hasPermission('manage mirador annotations'); |
|
|
|
foreach ($settings['mirador']['viewers'] as &$viewer) { |
|
$viewer['annotation'] = [ |
|
'adapter' => 'drupal', |
|
'endpoint' => $endpoint, |
|
'csrfTokenUrl' => Url::fromRoute('system.csrftoken', [], ['absolute' => TRUE])->toString(), |
|
'user' => $account->isAuthenticated() ? $account->getDisplayName() : 'Anonymous', |
|
'readonly' => !$can_manage, |
|
'allowTargetShapesStyling' => TRUE, |
|
'exportLocalStorageAnnotations' => FALSE, |
|
]; |
|
|
|
$viewer['annotations'] = [ |
|
'htmlSanitizationRuleSet' => 'liberal', |
|
]; |
|
|
|
$viewer['window'] = $viewer['window'] ?? []; |
|
$viewer['window']['defaultSideBarPanel'] = 'annotations'; |
|
} |
|
}
|
|
|