Skip to content

Commit

Permalink
UHF-9024: Fetch documents in current language
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Nov 8, 2023
1 parent c14ad8f commit 3a6fb02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,19 @@ public function getDocumentFromEntity(NodeInterface $entity, string $document_ty
return NULL;
}

$document = NULL;
foreach ($entity->get('field_meeting_documents') as $field) {
$json = json_decode($field->value, TRUE);
if ($langcode && isset($json['Language']) && strpos($json['Language'], $langcode) === FALSE) {

if ($langcode && isset($json['Language']) && !str_contains($json['Language'], $langcode)) {
continue;
}

if (isset($json['Type']) && isset($json['NativeId']) && $json['Type'] === $document_type) {
$document = $json;
break;
return $json;
}
}

return $document;
return NULL;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1500,38 +1500,29 @@ public function getMeetingAgenda(string $meetingId): ?array {
throw new NotFoundHttpException();
}

$meeting_timestamp = strtotime($meeting->get('field_meeting_date')->value);

$dateLong = date('d.m.Y', $meeting_timestamp);
$meetingNumber = $meeting->get('field_meeting_sequence_number')->value;
$meetingYear = date('Y', $meeting_timestamp);
$policymaker_title = $this->policymaker->get('field_ahjo_title')->value;
$agendaItems = NULL;
$publishDate = NULL;
$fileUrl = NULL;

// Use either current language or fallback language for agenda items.
$currentLanguage = $this->languageManager->getCurrentLanguage()->getId();
if ($currentLanguage === 'fi') {
$fallbackLanguage = 'sv';
}
else {
$fallbackLanguage = 'fi';
}
$fallbackLanguage = match ($currentLanguage) {
'fi' => 'sv',
default => 'fi',
};

if ($document = $this->meetingService->getDocumentFromEntity($meeting, 'pöytäkirja', 'fi')) {
$pageTitle = t('Minutes');
$documentTitle = t('Minutes publication date');
}
elseif ($document = $this->meetingService->getDocumentFromEntity($meeting, 'pöytäkirja', 'sv')) {
if ($document = $this->meetingService->getDocumentFromEntity($meeting, 'pöytäkirja', $currentLanguage)) {
$pageTitle = t('Minutes');
$documentTitle = t('Minutes publication date');
}
elseif ($document = $this->meetingService->getDocumentFromEntity($meeting, 'esityslista', 'fi')) {
elseif ($document = $this->meetingService->getDocumentFromEntity($meeting, 'esityslista', $currentLanguage)) {
$pageTitle = t('Agenda');
$documentTitle = t('Agenda publication date');
}
elseif ($document = $this->meetingService->getDocumentFromEntity($meeting, 'esityslista', 'sv')) {
elseif ($document = $this->meetingService->getDocumentFromEntity($meeting, 'pöytäkirja', $fallbackLanguage)) {
$pageTitle = t('Minutes');
$documentTitle = t('Minutes publication date');
}
elseif ($document = $this->meetingService->getDocumentFromEntity($meeting, 'esityslista', $fallbackLanguage)) {
$pageTitle = t('Agenda');
$documentTitle = t('Agenda publication date');
}
Expand All @@ -1545,9 +1536,6 @@ public function getMeetingAgenda(string $meetingId): ?array {
$document_timestamp = strtotime($document['Issued']);
$publishDate = date('d.m.Y', $document_timestamp);
}
else {
$publishDate = NULL;
}

$fileUrl = $this->meetingService->getUrlFromAhjoDocument($document);
}
Expand All @@ -1565,7 +1553,7 @@ public function getMeetingAgenda(string $meetingId): ?array {
$newList[$key] = $agendaItems[$key];
}
else {
$newList[$key] = $fallbackAgendaItems[$key];
$newList[$key] = $item;
}
}
$agendaItems = $newList;
Expand All @@ -1583,12 +1571,14 @@ public function getMeetingAgenda(string $meetingId): ?array {
// Decision announcement.
$decisionAnnouncement = $this->getDecisionAnnouncement($meeting, $currentLanguage, $agendaItems);

$meeting_timestamp = strtotime($meeting->get('field_meeting_date')->value);

return [
'meeting' => [
'nid' => $meeting->id(),
'page_title' => $pageTitle,
'date_long' => $dateLong,
'title' => $policymaker_title . ' ' . $meetingNumber . '/' . $meetingYear,
'date_long' => date('d.m.Y', $meeting_timestamp),
'title' => $this->getMeetingTitle($meeting),
],
'meeting_metadata' => $metadata,
'decision_announcement' => $decisionAnnouncement,
Expand Down

0 comments on commit 3a6fb02

Please sign in to comment.