fix page creation validation and persistence
Validate required page fields and localized translations, detect route collisions, and save pages and translations atomically with rollback on failure. Report creation errors while preserving submitted form values, safely encode Alpine.js values, and add English and German error messages. Return null for failed inserts and add page persistence tests.
This commit is contained in:
@@ -78,18 +78,24 @@ class WebsiteManager implements WebsiteManagerContract
|
||||
*/
|
||||
public function handleCreate()
|
||||
{
|
||||
$errorMessage = null;
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$pageRepository = new PageRepository;
|
||||
$page = $pageRepository->create($_POST);
|
||||
try {
|
||||
$pageRepository = new PageRepository;
|
||||
$page = $pageRepository->create($_POST);
|
||||
} catch (\Throwable) {
|
||||
$page = false;
|
||||
}
|
||||
if ($page) {
|
||||
phpb_redirect(phpb_url('website_manager'), [
|
||||
'message-type' => 'success',
|
||||
'message' => phpb_trans('website-manager.page-created')
|
||||
]);
|
||||
}
|
||||
$errorMessage = phpb_trans('website-manager.page-create-failed');
|
||||
}
|
||||
|
||||
$this->renderPageSettings();
|
||||
$this->renderPageSettings(null, $errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,7 +223,7 @@ class WebsiteManager implements WebsiteManagerContract
|
||||
*
|
||||
* @param PageContract $page
|
||||
*/
|
||||
public function renderPageSettings(?PageContract $page = null)
|
||||
public function renderPageSettings(?PageContract $page = null, ?string $errorMessage = null)
|
||||
{
|
||||
$action = isset($page) ? 'edit' : 'create';
|
||||
$theme = phpb_instance('theme', [
|
||||
|
||||
Reference in New Issue
Block a user