Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
WIP on #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Aug 3, 2020
1 parent 95da63d commit ce28d17
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
1 change: 0 additions & 1 deletion modules/doi_datacite/doi_datacite.module
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ function doi_datacite_form_node_form_alter(&$form, FormStateInterface $form_stat
$minter_id = Drupal::config('persistent_identifiers.settings')->get('persistent_identifiers_minter');
if ($minter_id == 'doi_datacite.minter.datacitedois') {
$minter_service = \Drupal::service('doi_datacite.minter.datacitedois');
// $node = \Drupal::entityTypeManager()->getStorage('node')->load($entity->id());
$datacite_metadata_values = $minter_service->getDataCiteElementValues($entity);
// DataCite requires the use of this following controlled list of resource types.
$resource_type_values = $minter_service->getResourceTypes();
Expand Down
8 changes: 7 additions & 1 deletion modules/doi_datacite/src/Minter/Dois.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public function mint($entity, $extra = NULL) {
global $base_url;
// If $extra is from the Views Bulk Operations Action
// or a Context Reaction (i.e., it's an array).
//
// At this point, $extra should have all the required metadata elements,
// either from the node itself or from the Action or Reaction config.
// @todo: check for missing required values and if any found, log details and return NULL.
if (is_array($extra)) {
$datacite_array = [];
$creators = explode(';', $extra['doi_datacite_creator']);
Expand Down Expand Up @@ -285,7 +289,9 @@ public function getDataCiteElementValues($node) {
if ($node->hasField($publication_year_field_name)) {
$node_publication_year_field_values = $node->get($publication_year_field_name)->getValue();
if (array_key_exists('value', $node_publication_year_field_values[0])) {
$datacite_values['publicationYear'] = $node_publication_year_field_values[0]['value'];
if (preg_match('/\d\d\d\d/', $node_publication_year_field_values[0]['value'], $matches)) {
$datacite_values['publicationYear'] = $matches[0];
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class MintDataCiteDoiAction extends ViewsBulkOperationsActionBase implements Vie
*/
public function execute($entity = NULL) {
$minter = \Drupal::service('doi_datacite.minter.datacitedois');
$datacite_metadata_values = $minter->getDataCiteElementValues($entity);

// @todo: merge values from $datacite_metadata_values with those from this reaction's
// config by looking for empty members of $datacite_metadata_values and populate them
// with values from the config. If some are still missing, skip and log. The minter will
// check for completeness and skip if values are missing.

$persister_id = \Drupal::config('persistent_identifiers.settings')->get('persistent_identifiers_persister');
$persister = \Drupal::service($persister_id);
// The values saved in this action's configuration form are in $this->configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ public function execute(EntityInterface $entity = NULL) {
}

$minter = \Drupal::service('doi_datacite.minter.datacitedois');
/*
// If any of the required metadata fields are empty, log and return.
$datacite_metadata_values = $minter->getDataCiteElementValues($node);

// @todo: merge values from $datacite_metadata_values with those from this reaction's
// config by looking for empty members of $datacite_metadata_values and populate them
// with values from the config. The minter will check for completeness and skip if
// values are missing.

// If any of the required metadata fields are empty, log and return.
$missing_properties = [];
foreach ($datacite_metadata_values as $key => $value) {
if (strlen($value) == 0) {
Expand All @@ -69,10 +74,9 @@ public function execute(EntityInterface $entity = NULL) {
\Drupal::logger('doi_datacite')->info(t("Cannot mint DOI for node \"@title\" (UUID @uuid) due to missing required metadata propert(ies) @keys.", ['@title' => $entity->get('title')->value, '@uuid' => $entity->uuid(), '@keys' => $keys]));
return;
}
*/

$persister = \Drupal::service($pid_config->get('persistent_identifiers_persister'));
$doi = $minter->mint($entity);
$doi = $minter->mint($entity, $datacite_metadata_values);
$persister->persist($entity, $doi, FALSE);
// Contexts using this reaction are fired in hook_presave, so there is no entity ID to log.
\Drupal::logger('doi_datacite')->info(t("DOI %pid minted for \"@title\" (UUID @uuid) via Context Reaction.", ['%pid' => $pid, '@title' => $entity->get('title')->value, '@uuid' => $entity->uuid()]));
Expand Down

0 comments on commit ce28d17

Please sign in to comment.