Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions modules/ezid/src/Minter/Ezid.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\ezid\Minter;

use Psr7\Message;
use Drupal\persistent_identifiers\MinterInterface;
use GuzzleHttp\Exception\RequestException;

Expand Down Expand Up @@ -73,7 +72,6 @@ public function mint($entity, $extra = NULL) {
'headers' => ['Content-Type' => 'text/plain; charset=UTF-8'],
'body' => $data,
]);
\Drupal::logger('persistent identifiers')->info(print_r($request, TRUE));
$message = $request->getBody();
if (strpos($message, "success: ") === 0) {
return substr($message, 9);
Expand All @@ -82,9 +80,9 @@ public function mint($entity, $extra = NULL) {
return FALSE;
}
catch (RequestException $e) {
$message = Message::toString($e->getRequest());
$message = $e->getRequest()->getUri();
if ($e->hasResponse()) {
$message = $message . "\n" . Message::toString($e->getResponse());
$message .= "\n" . $e->getResponse()->getBody();
}
\Drupal::logger('persistent identifiers')->error(preg_replace('/Authorization: Basic \w+/', 'Authentication Redacted', $message));
return FALSE;
Expand Down
19 changes: 11 additions & 8 deletions persistent_identifiers.module
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,21 @@ function persistent_identifiers_jsonld_alter_normalized_array(EntityInterface $e
$doi_field_name = $config->get('persistent_identifiers_target_field');
if ($entity->hasField($doi_field_name)) {
$doi_field_values = $entity->get($doi_field_name)->getValue();
if (array_key_exists('value', $doi_field_values[0])) {
$doi = $doi_field_values[0]['value'];
}
$identifiers = array_filter(array_map(
fn($value): string => (isset($value['value'])) ? $value['value'] : "",
$doi_field_values
));
}

if (isset($normalized['@graph'])) {
if (strlen($doi) && !is_array($normalized["@graph"])) {
$normalized['@graph'] = [$normalized['@graph']];
foreach ($identifiers as $id) {
if (strlen($id) && !is_array($normalized["@graph"])) {
$normalized['@graph'] = [$normalized['@graph']];
}
$normalized['@graph'][0]['http://schema.org/sameAs'][] = [
'@id' => $resolver_base_url . $id,
];
}
$normalized['@graph'][0]['http://schema.org/sameAs'][] = [
'@id' => $resolver_base_url . $doi,
];
}
}
}
2 changes: 1 addition & 1 deletion src/Plugin/Form/PersistentIdentifiersSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#weight' => 100,
'#type' => 'checkbox',
'#default_value' => $config->get('persistent_identifiers_map_to_schema_sameas'),
'#description' => $this->t("Add the persistent identifier to the node's JSON-LD as schema:sameAs, prepending the URL configured below. If the field is multivalued, uses the first value."),
'#description' => $this->t("Add the persistent identifier to the node's JSON-LD as schema:sameAs, prepending the URL configured below."),
'#title' => $this->t('Map to schema:sameAs in JSON-LD'),
'#attributes' => [
'id' => 'persistent_identifiers_map_to_schema_sameas',
Expand Down