Browse Source

make rdf namespaces configurable

pull/831/head
Seth Shaw 5 years ago
parent
commit
4a1696ea00
  1. 52
      config/install/islandora.settings.yml
  2. 12
      config/schema/islandora.schema.yml
  3. 29
      islandora.module
  4. 43
      src/Form/IslandoraSettingsForm.php

52
config/install/islandora.settings.yml

@ -2,3 +2,55 @@ broker_url: 'tcp://localhost:61613'
jwt_expiry: '+2 hour' jwt_expiry: '+2 hour'
gemini_url: '' gemini_url: ''
gemini_pseudo_bundles: [] gemini_pseudo_bundles: []
rdf_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/',

12
config/schema/islandora.schema.yml

@ -22,6 +22,18 @@ islandora.settings:
label: 'List of node, media and taxonomy terms that should include the linked Fedora URI' label: 'List of node, media and taxonomy terms that should include the linked Fedora URI'
sequence: sequence:
type: string type: string
rdf_namespaces:
type: sequence
label: 'RDF Namespaces'
sequence:
type: mapping
mapping:
prefix:
type: string
label: 'RDF Prefix'
namespace:
type: string
label: 'Fully Qualified RDF Namespace'
action.configuration.emit_node_event: action.configuration.emit_node_event:

29
islandora.module

@ -47,25 +47,16 @@ function islandora_help($route_name, RouteMatchInterface $route_match) {
* Implements hook_rdf_namespaces(). * Implements hook_rdf_namespaces().
*/ */
function islandora_rdf_namespaces() { function islandora_rdf_namespaces() {
// Yes, it's amazing, rdf is not registered by default! $config = \Drupal::config('islandora.settings');
return [ $namespace_config = $config->get('rdf_namespaces');
'ldp' => 'http://www.w3.org/ns/ldp#', if (!is_array($namespace_config)) {
'dc11' => 'http://purl.org/dc/elements/1.1/', \Drupal::logger('islandora')->warning("RDF Map config is not an array. Please check your RDF namespaces configuration in islandora core settings.");
'dcterms' => 'http://purl.org/dc/terms/', }
'nfo' => 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/v1.1/', $namespaces = [];
'ebucore' => 'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#', foreach ($namespace_config as $namespace) {
'fedora' => 'http://fedora.info/definitions/v4/repository#', $namespaces[$namespace['prefix']] = $namespace['namespace'];
'owl' => 'http://www.w3.org/2002/07/owl#', }
'ore' => 'http://www.openarchives.org/ore/terms/', return $namespaces;
'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/',
];
} }
/** /**

43
src/Form/IslandoraSettingsForm.php

@ -34,6 +34,7 @@ class IslandoraSettingsForm extends ConfigFormBase {
'month', 'month',
'year', 'year',
]; ];
const RDF_NAMESPACES = 'rdf_namespaces';
/** /**
* To list the available bundle types. * To list the available bundle types.
@ -184,6 +185,17 @@ class IslandoraSettingsForm extends ConfigFormBase {
'#default_value' => $selected_bundles, '#default_value' => $selected_bundles,
], ],
]; ];
$rdf_namespaces = '';
foreach ($config->get('rdf_namespaces') as $namespace) {
$rdf_namespaces .= $namespace['prefix'] . '|' . $namespace['namespace'] . "\n";
}
$form[self::RDF_NAMESPACES] = [
'#type' => 'textarea',
'#title' => $this->t('RDF Namespaces'),
'#default_value' => $rdf_namespaces,
];
return parent::buildForm($form, $form_state); return parent::buildForm($form, $form_state);
} }
@ -259,6 +271,22 @@ class IslandoraSettingsForm extends ConfigFormBase {
); );
} }
} }
// Validate RDF Namespaces.
foreach (preg_split("/[\r\n]+/", $form_state->getValue(self::RDF_NAMESPACES)) as $line) {
if (empty($line)) {
continue;
}
$namespace = explode("|", trim($line));
if (empty($namespace[0]) || empty($namespace[1])) {
$form_state->setErrorByName(
self::RDF_NAMESPACES,
$this->t("RDF Namespace form is malformed on line '@line'",
['@line' => trim($line)]
)
);
}
}
} }
/** /**
@ -285,10 +313,25 @@ class IslandoraSettingsForm extends ConfigFormBase {
} }
} }
$namespaces_array = [];
foreach (preg_split("/[\r\n]+/", $form_state->getValue(self::RDF_NAMESPACES)) as $line) {
if (empty($line)) {
continue;
}
$namespace = explode("|", trim($line));
if (!empty($namespace[0]) && !empty($namespace[1])) {
$namespaces_array[] = [
'prefix' => trim($namespace[0]),
'namespace' => trim($namespace[1]),
];
}
}
$config $config
->set(self::BROKER_URL, $form_state->getValue(self::BROKER_URL)) ->set(self::BROKER_URL, $form_state->getValue(self::BROKER_URL))
->set(self::JWT_EXPIRY, $form_state->getValue(self::JWT_EXPIRY)) ->set(self::JWT_EXPIRY, $form_state->getValue(self::JWT_EXPIRY))
->set(self::GEMINI_PSEUDO, $pseudo_types) ->set(self::GEMINI_PSEUDO, $pseudo_types)
->set(self::RDF_NAMESPACES, $namespaces_array)
->save(); ->save();
parent::submitForm($form, $form_state); parent::submitForm($form, $form_state);

Loading…
Cancel
Save