Skip to content

Commit

Permalink
Reuse the validation error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianallgeier committed Dec 7, 2024
1 parent 79782ad commit 5dedcc3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions config/sections/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,15 @@
}

$ids = $this->requestBody('ids');
$min = $section->min();

// check if the section has enough files after the deletion
if ($section->total() - count($ids) < $section->min()) {
if ($section->total() - count($ids) < $min) {
throw new Exception(
message: 'The section needs to have at least ' . $section->min() . ' files',
message: I18n::template('error.section.files.min.' . I18n::form($min), [
'min' => $min,
'section' => $section->headline()
])
);
}

Expand Down
8 changes: 6 additions & 2 deletions config/sections/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,15 @@
}

$ids = $this->requestBody('ids');
$min = $section->min();

// check if the section has enough pages after the deletion
if ($section->total() - count($ids) < $section->min()) {
if ($section->total() - count($ids) < $min) {
throw new Exception(
message: 'The section needs to have at least ' . $section->min() . ' pages',
message: I18n::template('error.section.pages.min.' . I18n::form($min), [
'min' => $min,
'section' => $section->headline()
])
);
}

Expand Down

0 comments on commit 5dedcc3

Please sign in to comment.