protected function MarcEncoder::processEntries in Bibliography & Citation 8
Same name and namespace in other branches
- 2.0.x modules/bibcite_marc/src/Encoder/MarcEncoder.php \Drupal\bibcite_marc\Encoder\MarcEncoder::processEntries()
Workaround about some things in MarcParser library.
Parameters
array $parsed: List of parsed entries.
1 call to MarcEncoder::processEntries()
- MarcEncoder::decode in modules/
bibcite_marc/ src/ Encoder/ MarcEncoder.php
File
- modules/
bibcite_marc/ src/ Encoder/ MarcEncoder.php, line 197
Class
- MarcEncoder
- Marc format encoder.
Namespace
Drupal\bibcite_marc\EncoderCode
protected function processEntries(array &$parsed) {
$config = \Drupal::config('bibcite_entity.mapping.marc');
$indexes = $config
->get('indexes');
foreach ($parsed as &$entry) {
if (count($entry) > 0) {
$entry['year'] = substr($entry['008'][0]->data, 7, 4);
$entry['lang'] = substr($entry['008'][0]->data, 35, 3);
foreach ($entry as $key => $value) {
switch ($key) {
case '000':
case '008':
unset($entry[$key]);
break;
case '100':
case '700':
$entity_key = 'authors';
foreach ($value as $i => $field) {
if ($field instanceof Field) {
foreach ($field->subfields as $j => $subfield) {
if ($entity_key) {
$entry[$entity_key][] = $subfield;
}
}
}
}
unset($entry[$key]);
break;
default:
if (is_array($value)) {
foreach ($value as $i => $field) {
if ($field instanceof Field) {
foreach ($field->subfields as $j => $subfield) {
$entity_key = array_search(implode('_', [
$key,
$field->ind1 === ' ' ? '' : $field->ind1,
$field->ind2 === ' ' ? '' : $field->ind2,
$j,
]), $indexes);
if (!$entity_key) {
$entity_key = array_search(implode('_', [
$key,
$field->ind1 === ' ' ? '' : $field->ind1,
$field->ind2 === ' ' ? '#' : $field->ind2,
$j,
]), $indexes);
}
if ($entity_key) {
if (isset($entry[$entity_key])) {
if (!is_array($entry[$entity_key])) {
$val = $entry[$entity_key];
unset($entry[$entity_key]);
$entry[$entity_key][] = $val;
}
$entry[$entity_key][] = $subfield;
}
else {
$entry[$entity_key] = $subfield;
}
}
}
}
}
unset($entry[$key]);
}
break;
}
}
}
}
}