Drupal modules for browsing and managing Fedora-based digital repositories.
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.

168 lines
4.4 KiB

<?php
/**
* @file
* Contains islandora.module.
*
* This file is part of the Islandora Project.
*
* (c) Islandora Foundation
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Diego Pino Navarro <dpino@metro.org> https://github.com/diegopino
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\islandora\ContextProvider\NodeContextProvider;
use Drupal\islandora\ContextProvider\MediaContextProvider;
use Drupal\islandora\ContextProvider\FileContextProvider;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function islandora_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the islandora module.
case 'help.page.islandora':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Islandora integrates Drupal with a Fedora repository.') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_rdf_namespaces().
*/
function islandora_rdf_namespaces() {
// Yes, it's amazing, rdf is not registered by default!
return [
'ldp' => 'http://www.w3.org/ns/ldp#',
'dc11' => 'http://purl.org/dc/elements/1.1/',
'nfo' => 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.1/',
'ebucore' => 'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#',
'fedora' => 'http://fedora.info/definitions/v4/repository#',
'owl' => 'http://www.w3.org/2002/07/owl#',
'ore' => 'http://www.openarchives.org/ore/terms/',
'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'islandora' => 'http://islandora.ca/CLAW/',
'pcdm' => 'http://pcdm.org/models#',
'use' => 'http://pcdm.org/use#',
'iana' => 'http://www.iana.org/assignments/relation/',
];
}
/**
* Implements hook_entity_insert().
*/
function islandora_entity_insert(EntityInterface $entity) {
switch ($entity->getEntityType()->id()) {
case "node":
$provider = new NodeContextProvider($entity);
break;
case "media":
$provider = new MediaContextProvider($entity);
break;
case "file":
$provider = new FileContextProvider($entity);
break;
default:
$provider = NULL;
break;
}
if ($provider) {
$context_manager = \Drupal::service('context.manager');
$provided = $provider->getRuntimeContexts([]);
$context_manager->evaluateContexts($provided);
foreach ($context_manager->getActiveReactions('index') as $reaction) {
$reaction->execute($entity);
}
}
}
/**
* Implements hook_entity_update().
*/
function islandora_entity_update(EntityInterface $entity) {
switch ($entity->getEntityType()->id()) {
case "node":
$provider = new NodeContextProvider($entity);
break;
case "media":
$provider = new MediaContextProvider($entity);
break;
case "file":
$provider = new FileContextProvider($entity);
break;
default:
$provider = NULL;
break;
}
if ($provider) {
$context_manager = \Drupal::service('context.manager');
$provided = $provider->getRuntimeContexts([]);
$context_manager->evaluateContexts($provided);
foreach ($context_manager->getActiveReactions('index') as $reaction) {
$reaction->execute($entity);
}
}
}
/**
* Implements hook_entity_delete().
*/
function islandora_entity_delete(EntityInterface $entity) {
switch ($entity->getEntityType()->id()) {
case "node":
$provider = new NodeContextProvider($entity);
break;
case "media":
$provider = new MediaContextProvider($entity);
break;
case "file":
$provider = new FileContextProvider($entity);
break;
default:
$provider = NULL;
break;
}
if ($provider) {
$context_manager = \Drupal::service('context.manager');
$provided = $provider->getRuntimeContexts([]);
$context_manager->evaluateContexts($provided);
foreach ($context_manager->getActiveReactions('delete') as $reaction) {
$reaction->execute($entity);
}
}
}
/**
* Implements hook_jsonld_alter_normalized_array().
*/
function islandora_jsonld_alter_normalized_array(EntityInterface $entity, array &$normalized, array $context) {
$context_manager = \Drupal::service('context.manager');
foreach ($context_manager->getActiveReactions('\Drupal\islandora\ContextReaction\NormalizerAlterReaction') as $reaction) {
$reaction->execute($entity, $normalized, $context);
}
}