Skip to content

Commit

Permalink
Merge pull request #1743 from danskernesdigitalebibliotek/DDFHER-119_…
Browse files Browse the repository at this point in the history
…expand-event-api

Expand event API to include `partners` as array string. DDFHER-119
  • Loading branch information
rasben authored Dec 3, 2024
2 parents 3c4d9b0 + 4c77bf9 commit 065f2a7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
8 changes: 8 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,14 @@
"description": "The name of a tag."
}
},
"partners": {
"type": "array",
"description": "The partners associated with the event.",
"items": {
"type": "string",
"description": "The name of a partner."
}
},
"ticket_categories": {
"type": "array",
"description": "Ticket categories used for the event. Not present for events without ticketing.",
Expand Down
39 changes: 39 additions & 0 deletions packages/cms-api/Model/EventsGET200ResponseInner.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ public function getPluginDefinition(): array {
'description' => 'The name of a tag.',
],
],
'partners' => [
'type' => 'array',
'description' => 'The partners associated with the event.',
'items' => [
'type' => 'string',
'description' => 'The name of a partner.',
],
],
'ticket_categories' => [
'type' => 'array',
'description' => 'Ticket categories used for the event. Not present for events without ticketing.',
Expand Down
20 changes: 20 additions & 0 deletions web/modules/custom/dpl_event/src/Services/EventRestMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function getResponse(EventInstance $event_instance): EventsGET200Response
'branches' => $this->getBranches(),
'address' => $this->getAddress(),
'tags' => $this->getTags(),
'partners' => $this->getMultiValue('event_partners'),
'ticketCapacity' => $this->getValue('event_ticket_capacity'),
'ticketCategories' => $this->getTicketCategories(),
'createdAt' => $this->getDateField('created'),
Expand Down Expand Up @@ -252,6 +253,25 @@ private function getDateField(string $field_name): ?DateTime {
return $date;
}

/**
* Get multiple string values as an array output.
*
* @return string[]
* An array of string values.
*/
private function getMultiValue(string $field_name): array {
$field = $this->eventWrapper->getField($field_name);

if (!($field instanceof FieldItemListInterface)) {
return [];
}

$values = $field->getValue();

// Turning the value keys into a simple, one-level array of strings.
return array_column($values, 'value');
}

/**
* Get string value of a possible field (or fallback field).
*/
Expand Down

0 comments on commit 065f2a7

Please sign in to comment.