diff --git a/src/Plugin/views/style/Record.php b/src/Plugin/views/style/Record.php index 8d44384..32bea8c 100644 --- a/src/Plugin/views/style/Record.php +++ b/src/Plugin/views/style/Record.php @@ -177,10 +177,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { public function render() { $rows = $this->getResultRows(); - /** @var \Drupal\views_oai_pmh\Plugin\MetadataPrefixInterface $currentPrefixPlugin */ - $currentPrefixPlugin = $this->prefixManager->createInstance( - $this->displayHandler->getCurrentMetadataPrefix() - ); + try { + /** @var \Drupal\views_oai_pmh\Plugin\MetadataPrefixInterface $currentPrefixPlugin */ + $currentPrefixPlugin = $this->prefixManager->createInstance( + $this->displayHandler->getCurrentMetadataPrefix() + ); + } catch(\Exception $e) { + return; + } $records = []; foreach ($rows as $row_id => $row) { @@ -190,7 +194,7 @@ public function render() { $elements = $this->rowToXml->transform($row); $element_or_null = [ - array_keys($elements)[0] => reset($elements) + array_keys($elements)[0] ?? NULL => reset($elements) ]; // Insure we're adding (union) arrays, not null. $element = $element_or_null ? $element_or_null : array(); @@ -202,7 +206,7 @@ public function render() { $data = $root_elements + $elements; // path id for datacite, dcc or dc - $path_id = (!empty($data['identifier']))? $data['identifier']['#'] : $data['dc:identifier']['#']; + $path_id = (!empty($data['identifier'])) ? $data['identifier']['#'] : (!empty($data['dc:identifier']) ? $data['dc:identifier']['#'] : ''); $xmlDoc = new \DOMDocument(); $xmlDoc->loadXML($this->serializer->encode($data, 'xml', [ @@ -427,11 +431,11 @@ protected function populateRow($row_id, ResultRow $row): array { try { $value = $this->view->style_plugin->getField($row_id, $id); - if ($field->option['hide_empty'] && empty($value)) { + if ($field->options['hide_empty'] && empty($value)) { continue; } - if(isset($field->option['type']) && $field->options['type'] == "datetime_default") { + if(isset($field->options['type']) && $field->options['type'] == "datetime_default") { $value = \Drupal::service('date.formatter')->format( strtotime($value), $field->options['settings']['format_type'] ); @@ -467,7 +471,8 @@ protected function populateRow($row_id, ResultRow $row): array { * @return array|null */ protected function getFieldKeyAlias($id) { - $fields = $this->options['field_mappings'][$this->displayHandler->getCurrentMetadataPrefix()]; + $prefix = $this->displayHandler->getCurrentMetadataPrefix(); + $fields = $this->options['field_mappings'][$prefix] ?? NULL; if (isset($fields) && isset($fields[$id]) && $fields[$id] !== 'none') { return $fields[$id]; diff --git a/src/Service/FormatRowToXml.php b/src/Service/FormatRowToXml.php index 1b64d84..5dc0160 100644 --- a/src/Service/FormatRowToXml.php +++ b/src/Service/FormatRowToXml.php @@ -126,7 +126,8 @@ public function transform(array $row): array { $this->depth($alias, $current_value) ); } - $output = array_map(array($this, "trimmingKeys"), $output); + + $output = array_map(fn (array $item): array => $this->trimmingKeys($item), $output); return $output; } @@ -147,7 +148,8 @@ public function trimmingKeys(&$array) { unset($array[$key]); } } - return array_map(array($this, "trimmingKeys"), $array); + + return array_map(fn (mixed $item): mixed => $this->trimmingKeys($item), $array); } else { return $array; diff --git a/src/Service/Repository.php b/src/Service/Repository.php index 54595e3..039e93e 100644 --- a/src/Service/Repository.php +++ b/src/Service/Repository.php @@ -32,6 +32,8 @@ class Repository implements RepositoryInterface { protected $totalRecords = 0; + protected array $formats = []; + /** * */