Skip to content

Commit

Permalink
Merge pull request #1584 from danskernesdigitalebibliotek/DDFHER-60_r…
Browse files Browse the repository at this point in the history
…edia-events

Creating a legacy Redia RSS feed for events. DDFHER-60
  • Loading branch information
kasperg authored Oct 8, 2024
2 parents baa9071 + 7cb5bc7 commit 6565b36
Show file tree
Hide file tree
Showing 16 changed files with 488 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
uuid: 014a5ed5-1c85-432f-a1b8-3814869178fd
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.media.redia_feed_large
- field.field.media.image.field_byline
- field.field.media.image.field_media_image
- image.style.redia_feed_large
- media.type.image
module:
- image
id: media.image.redia_feed_large
targetEntityType: media
bundle: image
mode: redia_feed_large
content:
field_media_image:
type: image
label: hidden
settings:
image_link: ''
image_style: redia_feed_large
image_loading:
attribute: lazy
third_party_settings: { }
weight: 0
region: content
hidden:
created: true
field_byline: true
langcode: true
name: true
search_api_excerpt: true
thumbnail: true
uid: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
uuid: 7cd49745-6747-4b76-b64a-f3e2a22a338e
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.media.redia_feed_small
- field.field.media.image.field_byline
- field.field.media.image.field_media_image
- image.style.redia_feed_small
- media.type.image
module:
- image
id: media.image.redia_feed_small
targetEntityType: media
bundle: image
mode: redia_feed_small
content:
field_media_image:
type: image
label: hidden
settings:
image_link: ''
image_style: redia_feed_small
image_loading:
attribute: lazy
third_party_settings: { }
weight: 0
region: content
hidden:
created: true
field_byline: true
langcode: true
name: true
search_api_excerpt: true
thumbnail: true
uid: true
11 changes: 11 additions & 0 deletions config/sync/core.entity_view_mode.media.redia_feed_large.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
uuid: 74eba980-7ec0-4b81-a6da-5c33830b08d9
langcode: en
status: true
dependencies:
module:
- media
id: media.redia_feed_large
label: 'Redia feed - large'
description: ''
targetEntityType: media
cache: true
11 changes: 11 additions & 0 deletions config/sync/core.entity_view_mode.media.redia_feed_small.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
uuid: fd0b39a0-f244-4d82-af84-54c63cf451bc
langcode: en
status: true
dependencies:
module:
- media
id: media.redia_feed_small
label: 'Redia feed - small'
description: ''
targetEntityType: media
cache: true
1 change: 1 addition & 0 deletions config/sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module:
dpl_react: 0
dpl_react_apps: 0
dpl_recommender: 0
dpl_redia_legacy: 0
dpl_related_content: 0
dpl_reservations: 0
dpl_rest_base: 0
Expand Down
15 changes: 15 additions & 0 deletions config/sync/image.style.redia_feed_large.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
uuid: 923e70e6-ea34-446d-ae06-2f6ac0ac4f00
langcode: en
status: true
dependencies: { }
name: redia_feed_large
label: 'Redia feed large'
effects:
71f3eb2a-c6f8-4a85-a16f-651a6e43239e:
uuid: 71f3eb2a-c6f8-4a85-a16f-651a6e43239e
id: image_scale
weight: 1
data:
width: 2000
height: null
upscale: false
15 changes: 15 additions & 0 deletions config/sync/image.style.redia_feed_small.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
uuid: 33f9623f-9eea-4b05-8e9c-f1d3ac224119
langcode: en
status: true
dependencies: { }
name: redia_feed_small
label: 'Redia feed small'
effects:
2cd37185-a9d4-43e1-ba81-66b73d18cae2:
uuid: 2cd37185-a9d4-43e1-ba81-66b73d18cae2
id: image_scale
weight: 1
data:
width: 220
height: null
upscale: true
41 changes: 34 additions & 7 deletions web/modules/custom/dpl_event/src/EventWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ private function getDate(string $value): \DateTimeInterface {
return new DateTimeImmutable($event_date_values[$value], new \DateTimeZone('UTC'));
}

/**
* Getting an events branches.
*
* @return array<NodeInterface>|null
* The matching branches.
*/
public function getBranches(): ?array {
$field = $this->getField('branch');

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

return $field->referencedEntities() ?? NULL;
}

/**
* Load an eventinstance address - either from the series/instance or branch.
*/
Expand All @@ -96,15 +112,10 @@ public function getAddressField(): ?FieldItemListInterface {
return $instance_field;
}

// Could not find data - look up address from branch instead.
$branch_field = $this->getField('branch');

if (!$branch_field instanceof FieldItemListInterface) {
return NULL;
}
// Could not find data - look up address from first branch instead.
$branch = $this->getBranches()[0] ?? NULL;

$branch_address_field = 'field_address';
$branch = $branch_field->referencedEntities()[0] ?? NULL;

if (!($branch instanceof NodeInterface) || !$branch->hasField($branch_address_field)) {
return NULL;
Expand All @@ -113,6 +124,22 @@ public function getAddressField(): ?FieldItemListInterface {
return $branch->get($branch_address_field);
}

/**
* Getting the description, from the first available text paragraph.
*/
public function getDescription(): ?string {
/** @var \Drupal\paragraphs\ParagraphInterface[] $paragraphs */
$paragraphs = $this->event->get('event_paragraphs')->referencedEntities();

foreach ($paragraphs as $paragraph) {
if ($paragraph->bundle() === 'text_body') {
return $paragraph->get('field_body')->getValue()[0]['value'] ?? NULL;
}
}

return NULL;
}

/**
* Get the EventState object of an eventinstance.
*/
Expand Down
21 changes: 2 additions & 19 deletions web/modules/custom/dpl_event/src/Services/EventRestMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getResponse(EventInstance $event_instance): EventsGET200Response
'url' => $this->event->toUrl()->setAbsolute(TRUE)->toString(TRUE)->getGeneratedUrl(),
'ticketManagerRelevance' => !empty($this->getSeriesValue('field_relevant_ticket_manager')),
'description' => $this->getValue('event_description'),
'body' => $this->getDescription(),
'body' => $this->eventWrapper->getDescription(),
'state' => $this->eventWrapper->getState()?->value,
'image' => $this->getImage(),
'branches' => $this->getBranches(),
Expand All @@ -84,8 +84,7 @@ public function getResponse(EventInstance $event_instance): EventsGET200Response
private function getBranches(): array {
$names = [];

/** @var \Drupal\node\NodeInterface[] $branches */
$branches = $this->event->get('branch')->referencedEntities();
$branches = $this->eventWrapper->getBranches() ?? [];

foreach ($branches as $branch) {
$label = $branch->getTitle();
Expand Down Expand Up @@ -117,22 +116,6 @@ private function getTags(): array {
return $names;
}

/**
* Getting the description, from the first available text paragraph.
*/
private function getDescription(): ?string {
/** @var \Drupal\paragraphs\ParagraphInterface[] $paragraphs */
$paragraphs = $this->event->get('event_paragraphs')->referencedEntities();

foreach ($paragraphs as $paragraph) {
if ($paragraph->bundle() === 'text_body') {
return $paragraph->get('field_body')->getValue()[0]['value'] ?? NULL;
}
}

return NULL;
}

/**
* Getting the external data, supplied by third party PATCH.
*/
Expand Down
9 changes: 9 additions & 0 deletions web/modules/custom/dpl_redia_legacy/dpl_redia_legacy.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "DPL Redia Legacy feeds"
type: module
description: "Various legacy integrations, used for the Redia App."
package: DPL
core_version_requirement: ^10

dependencies:
- dpl_opening_hours:dpl_opening_hours
- drupal:drupal_typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dpl_redia_legacy.events:
path: "/ding-redia-rss/event"
defaults:
_controller: '\Drupal\dpl_redia_legacy\Controller\RssFeeds\EventsController::getFeed'
_title: "Redia APP Event"
requirements:
_permission: "access content"
options:
_format: "xml"
Loading

0 comments on commit 6565b36

Please sign in to comment.