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.
118 lines
3.7 KiB
118 lines
3.7 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\Database\IntegrityConstraintViolationException; |
|
use Drupal\Core\Entity\EntityInterface; |
|
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_modules_installed(). |
|
*/ |
|
function islandora_modules_installed($modules) { |
|
// Ensure the auth and serialization formats we need are available. |
|
if (in_array('rest', $modules)) { |
|
$rest_resource_config_storage = \Drupal::service('entity_type.manager')->getStorage('rest_resource_config'); |
|
$rest_resource_config = $rest_resource_config_storage->load('entity.node'); |
|
|
|
if ($rest_resource_config) { |
|
$configuration = $rest_resource_config->get('configuration'); |
|
|
|
if (!in_array('jsonld', $configuration['formats'])) { |
|
$configuration['formats'][] = 'jsonld'; |
|
} |
|
|
|
if (!in_array('jwt_auth', $configuration['authentication'])) { |
|
$configuration['authentication'][] = 'jwt_auth'; |
|
} |
|
|
|
$rest_resource_config->set('configuration', $configuration); |
|
$rest_resource_config->save(TRUE); |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* 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_TYPE_insert(). |
|
*/ |
|
function islandora_node_insert(EntityInterface $entity) { |
|
// Creates a record in the db to track the number of changes to the entity. |
|
$versionCounter = \Drupal::service('islandora.versioncounter'); |
|
try { |
|
$versionCounter->create($entity->uuid()); |
|
} |
|
catch (IntegrityConstraintViolationException $e) { |
|
\Drupal::logger('islandora')->error( |
|
'Attempted to create duplicate entry for @uuid in version counter ' . |
|
'table. This should never happen.', |
|
['@uuid' => $entity->uuid()] |
|
); |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_ENTITY_TYPE_update(). |
|
*/ |
|
function islandora_node_update(EntityInterface $entity) { |
|
// Increments the number of changes to the entity. |
|
$versionCounter = \Drupal::service('islandora.versioncounter'); |
|
$versionCounter->increment($entity->uuid()); |
|
} |
|
|
|
/** |
|
* Implements hook_ENTITY_TYPE_update(). |
|
*/ |
|
function islandora_node_delete(EntityInterface $entity) { |
|
// Deletes the record in the db to track the number of changes to the entity. |
|
$versionCounter = \Drupal::service('islandora.versioncounter'); |
|
$versionCounter->delete($entity->uuid()); |
|
}
|
|
|