Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template: exclude canva regions when no widgets are included in the template save #2911

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -532,7 +532,7 @@
* @throws NotFoundException
* @throws \Xibo\Support\Exception\ControllerNotImplemented
*/
function add(Request $request, Response $response)

Check failure on line 535 in lib/Controller/Template.php

View workflow job for this annotation

GitHub Actions / phpcs

Visibility must be declared on method "add"
{
$sanitizedParams = $this->getSanitizer($request->getParams());

Expand All @@ -559,7 +559,7 @@
}
$tags[] = $this->tagFactory->tagFromString('template');

$layout = $this->layoutFactory->createFromResolution($resolutionId,

Check failure on line 562 in lib/Controller/Template.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening parenthesis of a multi-line function call must be the last content on the line
$this->getUser()->userId,
$name,
$description,
Expand Down Expand Up @@ -656,7 +656,7 @@
* )
* )
*/
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 @@
$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 Expand Up @@ -731,7 +748,7 @@
* @throws GeneralException
* @throws \Xibo\Support\Exception\ControllerNotImplemented
*/
function addForm(Request $request, Response $response)

Check failure on line 751 in lib/Controller/Template.php

View workflow job for this annotation

GitHub Actions / phpcs

Visibility must be declared on method "addForm"
{
$this->getState()->template = 'template-form-add';
$this->getState()->setData([
Expand Down
Loading