Skip to content

Commit

Permalink
Layouts: Update canvas-only layout duration
Browse files Browse the repository at this point in the history
  • Loading branch information
mgbaybay committed Oct 17, 2024
1 parent aa724b7 commit 1a44e52
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/Controller/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,9 @@ public function saveElements(Request $request, Response $response, $id)
// Parse the element JSON to see if we need to set `itemsPerPage`
$slots = [];
$uniqueSlots = 0;
$isMediaOnlyWidget = true;
$maxDuration = 1;

foreach ($elementJson as $widgetElement) {
foreach ($widgetElement['elements'] ?? [] as $element) {
$slotNo = 'slot_' . ($element['slot'] ?? 0);
Expand All @@ -1796,10 +1799,13 @@ public function saveElements(Request $request, Response $response, $id)

if (!in_array($mediaId, $existingMediaIds)) {
// Make sure it exists, and we have permission to use it.
$this->mediaFactory->getById($mediaId, false);
$media = $this->mediaFactory->getById($mediaId, false);
$maxDuration = $media->duration ?? 10;
}
$widget->assignMedia($mediaId);
$newMediaIds[] = $mediaId;
} else {
$isMediaOnlyWidget = false;
}
}
}
Expand Down Expand Up @@ -1829,6 +1835,21 @@ public function saveElements(Request $request, Response $response, $id)
}
}

// Canvas-only layout without a custom duration
if ($widget->type == 'global' && $isMediaOnlyWidget && $widget->useDuration == 0) {
// Do we need to recalculate the duration?
if (count($newMediaIds) < count($existingMediaIds)) {
foreach ($newMediaIds as $newMediaId) {
$media = $this->mediaFactory->getById($newMediaId, false);
$maxDuration = max($media->duration, $maxDuration);
}
} else {
$maxDuration = max($widget->calculatedDuration, $maxDuration);
}

$widget->calculatedDuration = $maxDuration;
}

// Save, without auditing widget options.
$widget->save([
'saveWidgetOptions' => true,
Expand Down

0 comments on commit 1a44e52

Please sign in to comment.