Skip to content

Commit

Permalink
Template: exclude canva regions when no widgets are included in the t…
Browse files Browse the repository at this point in the history
…emplate save (#2911)

* Template: exclude canva regions when no widgets are included in the template save
fixes xibosignage/xibo#3574
  • Loading branch information
dasgarner authored Feb 12, 2025
1 parent 012d0f7 commit ba2d1d3
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/Controller/Template.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2024 Xibo Signage Ltd
* Copyright (C) 2025 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -656,7 +656,7 @@ function add(Request $request, Response $response)
* )
* )
*/
function addFromLayout(Request $request, Response $response, $id)
public function addFromLayout(Request $request, Response $response, $id): Response
{
// Get the layout
$layout = $this->layoutFactory->getById($id);
Expand Down Expand Up @@ -698,6 +698,23 @@ function addFromLayout(Request $request, Response $response, $id)
$this->checkRootFolderAllowSave();
}

// When saving a layout as a template, we should not include the empty canva region as that requires
// a widget to be inside it.
// https://github.com/xibosignage/xibo/issues/3574
if (!$includeWidgets) {
$this->getLog()->debug('addFromLayout: widgets have not been included, checking for empty regions');

$regionsWithWidgets = [];
foreach ($layout->regions as $region) {
if ($region->type === 'canvas') {
$this->getLog()->debug('addFromLayout: Canvas region excluded from export');
} else {
$regionsWithWidgets[] = $region;
}
}
$layout->regions = $regionsWithWidgets;
}

$layout->setOwner($this->getUser()->userId, true);
$layout->save();

Expand Down

0 comments on commit ba2d1d3

Please sign in to comment.