Skip to content

Commit

Permalink
Use more concise code returning short and sub title
Browse files Browse the repository at this point in the history
  • Loading branch information
David Maus committed Jan 4, 2024
1 parent 220c76d commit 5dae291
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions module/VuFind/src/VuFind/RecordDriver/DefaultRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -1210,14 +1210,8 @@ public function getSeries()
*/
public function getShortTitle()
{
if (array_key_exists('title_short', $this->fields)) {
if (is_array($this->fields['title_short'])) {
$title = $this->fields['title_short'][0];
} else {
$title = $this->fields['title_short'];
}
}
return $title ?? '';
$titles = (array)($this->fields['title_short'] ?? []);
return $titles[0] ?? '';
}

/**
Expand All @@ -1238,14 +1232,8 @@ public function getSource()
*/
public function getSubtitle()
{
if (array_key_exists('title_sub', $this->fields)) {
if (is_array($this->fields['title_sub'])) {
$subtitle = $this->fields['title_sub'][0];
} else {
$subtitle = $this->fields['title_sub'];
}
}
return $subtitle ?? '';
$titles = (array)($this->fields['title_sub'] ?? []);
return $titles[0] ?? '';
}

/**
Expand Down Expand Up @@ -1350,14 +1338,8 @@ public function getThumbnail($size = 'small')
*/
public function getTitle()
{
if (array_key_exists('title', $this->fields)) {
if (is_array($this->fields['title'])) {
$title = $this->fields['title'][0];
} else {
$title = $this->fields['title'];
}
}
return $title ?? '';
$titles = (array)($this->fields['title'] ?? []);
return $titles[0] ?? '';
}

/**
Expand Down

0 comments on commit 5dae291

Please sign in to comment.