From 56444554ef69e050e985f23ec5af688e753a8535 Mon Sep 17 00:00:00 2001 From: Seth Shaw Date: Tue, 27 Apr 2021 18:28:35 -0700 Subject: [PATCH] Move rdf namespaces into jsonld config (Issue-1520) (#832) * move rdf namespaces into jsonld config * Add form link to jsonld settings form --- islandora.install | 84 ++++++++++++++++++++++++++++++ islandora.module | 25 --------- src/Form/IslandoraSettingsForm.php | 8 +++ 3 files changed, 92 insertions(+), 25 deletions(-) diff --git a/islandora.install b/islandora.install index e4d94f9e..f9eb1225 100644 --- a/islandora.install +++ b/islandora.install @@ -5,6 +5,13 @@ * Install/update hook implementations. */ +/** + * Adds common namespaces to jsonld.settings. + */ +function islandora_install() { + update_jsonld_included_namespaces(); +} + /** * Delete the 'delete_media' action we used to provide, if it exists. * @@ -90,3 +97,80 @@ function islandora_update_8005() { } } } + +/** + * Adds adds previously hardcoded namespaces to configuration. + */ +function islandora_update_8006() { + update_jsonld_included_namespaces(); +} + +/** + * Used by install and update_8006 to add namespaces to jsonld.settings.yml. + */ +function update_jsonld_included_namespaces() { + $namespaces = [ + [ + 'prefix' => 'ldp', + 'namespace' => 'http://www.w3.org/ns/ldp#', + ], [ + 'prefix' => 'dc11', + 'namespace' => 'http://purl.org/dc/elements/1.1/', + ], [ + 'prefix' => 'dcterms', + 'namespace' => 'http://purl.org/dc/terms/', + ], [ + 'prefix' => 'nfo', + 'namespace' => 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.1/', + ], [ + 'prefix' => 'ebucore', + 'namespace' => 'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#', + ], [ + 'prefix' => 'fedora', + 'namespace' => 'http://fedora.info/definitions/v4/repository#', + ], [ + 'prefix' => 'owl', + 'namespace' => 'http://www.w3.org/2002/07/owl#', + ], [ + 'prefix' => 'ore', + 'namespace' => 'http://www.openarchives.org/ore/terms/', + ], [ + 'prefix' => 'rdf', + 'namespace' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + ], [ + 'prefix' => 'rdau', + 'namespace' => 'http://rdaregistry.info/Elements/u/', + ], [ + 'prefix' => 'islandora', + 'namespace' => 'http://islandora.ca/', + ], [ + 'prefix' => 'pcdm', + 'namespace' => 'http://pcdm.org/models#', + ], [ + 'prefix' => 'use', + 'namespace' => 'http://pcdm.org/use#', + ], [ + 'prefix' => 'iana', + 'namespace' => 'http://www.iana.org/assignments/relation/', + ], [ + 'prefix' => 'premis', + 'namespace' => 'http://www.loc.gov/premis/rdf/v1#', + ], [ + 'prefix' => 'premis3', + 'namespace' => 'http://www.loc.gov/premis/rdf/v3/', + ], [ + 'prefix' => 'co', + 'namespace' => 'http://purl.org/co/', + ], + ]; + + $config = \Drupal::configFactory()->getEditable('jsonld.settings'); + if ($config && !is_array($config->get('rdf_namespaces'))) { + $config->set('rdf_namespaces', $namespaces); + $config->save(TRUE); + } + else { + \Drupal::logger('islandora') + ->warning("Could not find required jsonld.settings to add default RDF namespaces."); + } +} diff --git a/islandora.module b/islandora.module index 0a86a6ac..738be5b4 100644 --- a/islandora.module +++ b/islandora.module @@ -43,31 +43,6 @@ function islandora_help($route_name, RouteMatchInterface $route_match) { } } -/** - * 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/', - 'dcterms' => 'http://purl.org/dc/terms/', - '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/', - 'pcdm' => 'http://pcdm.org/models#', - 'use' => 'http://pcdm.org/use#', - 'iana' => 'http://www.iana.org/assignments/relation/', - 'premis' => 'http://www.loc.gov/premis/rdf/v1#', - 'premis3' => 'http://www.loc.gov/premis/rdf/v3/', - 'co' => 'http://purl.org/co/', - ]; -} - /** * Implements hook_node_insert(). */ diff --git a/src/Form/IslandoraSettingsForm.php b/src/Form/IslandoraSettingsForm.php index cdaa358d..2e8513f0 100644 --- a/src/Form/IslandoraSettingsForm.php +++ b/src/Form/IslandoraSettingsForm.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Site\Settings; +use Drupal\Core\Url; use Stomp\Client; use Stomp\Exception\StompException; use Stomp\StatefulStomp; @@ -184,6 +185,13 @@ class IslandoraSettingsForm extends ConfigFormBase { '#default_value' => $selected_bundles, ], ]; + + $form['rdf_namespaces'] = [ + '#type' => 'link', + '#title' => $this->t('Update RDF namespace configurations in the JSON-LD module settings.'), + '#url' => Url::fromRoute('system.jsonld_settings'), + ]; + return parent::buildForm($form, $form_state); }