Skip to content

Commit

Permalink
Add setting to disable JSON-LD reverse (#2090)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimsafley committed Sep 11, 2023
1 parent ba01308 commit e2728c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Expand Up @@ -67,6 +67,8 @@ public function getJsonLdType()

public function getJsonLd()
{
$settings = $this->getServiceLocator()->get('Omeka\Settings');

// Set the date time value objects.
$dateTime = [
'o:created' => [
Expand Down Expand Up @@ -109,8 +111,11 @@ public function getJsonLd()
// According to the JSON-LD spec, the value of the @reverse key "MUST be
// a JSON object containing members representing reverse properties."
// Here, we include the key only if the resource has reverse properties.
$reverse = $this->subjectValuesForReverse();
$reverse = $reverse ? ['@reverse' => $reverse] : [];
$reverse = [];
if (!$settings->get('disable_jsonld_reverse')) {
$reverse = $this->subjectValuesForReverse();
$reverse = $reverse ? ['@reverse' => $reverse] : [];
}

return array_merge(
[
Expand Down
14 changes: 14 additions & 0 deletions application/src/Form/SettingForm.php
Expand Up @@ -187,6 +187,20 @@ public function init()
],
]);

$this->add([
'type' => 'checkbox',
'name' => 'disable_jsonld_reverse',
'options' => [
'element_group' => 'general',
'label' => 'Disable JSON-LD @reverse', // @translate
'info' => 'Disable JSON-LD reverse properties in the API output for resources.', // @translate
],
'attributes' => [
'value' => $this->settings->get('disable_jsonld_reverse'),
'id' => 'disable-jsonld-reverse',
],
]);

// Display element group

$this->add([
Expand Down

0 comments on commit e2728c8

Please sign in to comment.