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

Elements: add an API check to ensure we aren't trying to save a widget with no elements #2390

Merged
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
8 changes: 8 additions & 0 deletions lib/Controller/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@
* @SWG\Parameter(
* name="transitionDirection",
* in="formData",
* description="The direction for this transition, only appropriate for transitions that move, such as fly. Available options: N, NE, E, SE, S, SW, W, NW",

Check warning on line 787 in lib/Controller/Widget.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 164 characters
* type="integer",
* required=false
* ),
Expand Down Expand Up @@ -887,7 +887,7 @@
// Are we allowed to do this?
if ($widget->type === 'subplaylist') {
throw new InvalidArgumentException(
__('Audio cannot be attached to a Sub-Playlist Widget. Please attach it to the Widgets inside the Playlist'),

Check warning on line 890 in lib/Controller/Widget.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 125 characters
'type'
);
}
Expand Down Expand Up @@ -991,7 +991,7 @@
// Are we allowed to do this?
if ($widget->type === 'subplaylist') {
throw new InvalidArgumentException(
__('Audio cannot be attached to a Sub-Playlist Widget. Please attach it to the Widgets inside the Playlist'),

Check warning on line 994 in lib/Controller/Widget.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 125 characters
'type'
);
}
Expand Down Expand Up @@ -1658,6 +1658,14 @@
throw new InvalidArgumentException(__('Invalid element JSON'), 'body');
}

// Validate that we have elements remaining.
if (count($elementJson) <= 0) {
throw new InvalidArgumentException(
__('At least one element is required for this Widget. Please delete it if you no longer need it.'),
'body',
);
}

// Parse the element JSON to see if we need to set `itemsPerPage`
$slots = [];
$uniqueSlots = 0;
Expand Down
Loading