diff --git a/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php b/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php index 5c70a3747e0118ccd975d50feb0aad651003d721..af100947e782170f494626c5365b52ab1ad7988b 100644 --- a/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php +++ b/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php @@ -1141,6 +1141,8 @@ trait SolrMarcFincTrait { $retval = []; $defaultHeading = 'Note'; + // container for collecting recordIDs to the result array #12941 + $tempIds = []; $fields = $this->getMarcRecord()->getFields('787'); if (!$fields) { @@ -1156,24 +1158,57 @@ trait SolrMarcFincTrait ? $a->getData() . ': ' . $t->getData() : $a->getData(); + $linkFields = $field->getSubfields('w'); + foreach ($linkFields as $current) { + $ids = $current->getData(); + + // Extract parenthetical prefixes: + if (preg_match(self::BSZ_PATTERN, $ids, $matches)) { + // use the same key to set the record_id into the + // $retval array like it is used for the other + // content below + $tempIds[$i->getData()]['record_id'] + = $matches[2] . $matches[3]; + } + } // end foreach + + // add ids already here to the temporary array + // instead of the end of the function with the return value + $tempIds = $this->addFincIDToRecord($tempIds); + // does a linked record exist - $link = ($w = $field->getSubfield('w')) ? $w->getData() : ''; + $link = ($w = $field->getSubfield('w')) + ? $w->getData() : ''; - // we expect the links to be ppns prefixed with an ISIL so strip - // the ISIL + // we expect the links to be ppns prefixed with an ISIL so + // strip the ISIL $ppn = preg_replace( "/^\(([A-z])+\-([A-z0-9])+\)\s?/", "", $link ); - // let's use the main entry heading as associative key and push - // the gathered content into the retval array + $record_id = null; + if (!empty($tempIds[$i->getData()]['id'])) { + $record_id = $tempIds[$i->getData()]['record_id']; + } + + $id = null; + if (!empty($tempIds[$i->getData()]['id'])) { + $id = $tempIds[$i->getData()]['id']; + } + + // let's use the main entry heading as associative key and + // push the gathered content into the retval array + // add recordIDs 'record_id' and 'id' to the result array + // cmp. #12941 $retval[$i->getData()][] = [ 'text' => $text, - 'link' => (!empty($ppn) ? $ppn : $link) + 'link' => (!empty($ppn) ? $ppn : $link), + 'record_id' => $record_id, + 'id' => $id ]; } else { - // no main entry heading found, so push subfield a's content into - // retval using the defaultHeading + // no main entry heading found, so push subfield a's content + // into retval using the defaultHeading $retval[$defaultHeading][] = [ 'text' => $a->getData(), 'link' => '' @@ -1181,6 +1216,7 @@ trait SolrMarcFincTrait } } } + return $retval; }