You are here

private function EndnoteEncoder::decodeTagged in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_endnote/src/Encoder/EndnoteEncoder.php \Drupal\bibcite_endnote\Encoder\EndnoteEncoder::decodeTagged()

Decode tagged format function.

1 call to EndnoteEncoder::decodeTagged()
EndnoteEncoder::decode in modules/bibcite_endnote/src/Encoder/EndnoteEncoder.php

File

modules/bibcite_endnote/src/Encoder/EndnoteEncoder.php, line 390

Class

EndnoteEncoder
Endnote format encoder.

Namespace

Drupal\bibcite_endnote\Encoder

Code

private function decodeTagged($data) {
  $result = [];
  $config = \Drupal::config('bibcite_entity.mapping.tagged');
  $indexes = $config
    ->get('indexes');
  $data = explode("\n\n", $data);
  foreach ($data as $i => &$record) {
    $fields = explode("\n", $record);
    foreach ($fields as $field) {
      $key = array_search(substr($field, 0, 2), $indexes);
      $value = substr($field, 3);
      if ($key) {
        if (isset($result[$i][$key])) {
          if (is_array($result[$i][$key])) {
            $result[$i][$key][] = $value;
          }
          else {
            $val = $result[$i][$key];
            unset($result[$i][$key]);
            $result[$i][$key][] = $val;
            $result[$i][$key][] = $value;
          }
        }
        else {
          $result[$i][$key] = $value;
        }
      }
    }
  }
  return $result;
}