Implemented a block editor for changing the layout of the page
This commit is contained in:
@@ -4,32 +4,50 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use App\Models\PageBlock;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
trait ValidatesPreregistrationPageInput
|
||||
{
|
||||
/**
|
||||
* @return array<string, array<int, ValidationRule|string>>
|
||||
*/
|
||||
protected function preregistrationPageRules(): array
|
||||
protected function preregistrationPageSettingsRules(): array
|
||||
{
|
||||
return [
|
||||
'title' => ['required', 'string', 'max:255'],
|
||||
'heading' => ['required', 'string', 'max:255'],
|
||||
'intro_text' => ['nullable', 'string'],
|
||||
'thank_you_message' => ['nullable', 'string'],
|
||||
'expired_message' => ['nullable', 'string'],
|
||||
'ticketshop_url' => ['nullable', 'string', 'url:http,https', 'max:255'],
|
||||
'post_submit_redirect_url' => ['nullable', 'string', 'url:http,https', 'max:500'],
|
||||
'background_overlay_color' => ['nullable', 'string', 'regex:/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/'],
|
||||
'background_overlay_opacity' => ['nullable', 'integer', 'min:0', 'max:100'],
|
||||
'page_background' => ['nullable', 'file', 'image', 'mimes:jpeg,png,jpg,webp', 'max:5120'],
|
||||
'remove_page_background' => ['sometimes', 'boolean'],
|
||||
'start_date' => ['required', 'date'],
|
||||
'end_date' => ['required', 'date', 'after:start_date'],
|
||||
'phone_enabled' => ['sometimes', 'boolean'],
|
||||
'is_active' => ['sometimes', 'boolean'],
|
||||
'background_image' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp', 'max:5120'],
|
||||
'logo_image' => ['nullable', 'file', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function preparePreregistrationPageFields(): void
|
||||
/**
|
||||
* @return array<string, array<int, ValidationRule|string>>
|
||||
*/
|
||||
protected function preregistrationPageBlocksRules(): array
|
||||
{
|
||||
return [
|
||||
'blocks' => ['required', 'array', 'min:1'],
|
||||
'blocks.*.type' => ['required', 'string', Rule::in(PageBlock::TYPES)],
|
||||
'blocks.*.sort_order' => ['required', 'integer', 'min:0', 'max:9999'],
|
||||
'blocks.*.is_visible' => ['sometimes', 'boolean'],
|
||||
'blocks.*.content' => ['required', 'array'],
|
||||
'blocks.*.remove_block_image' => ['sometimes', 'boolean'],
|
||||
'blocks.*.block_image' => ['nullable', 'file', 'mimes:jpeg,png,jpg,webp,svg', 'max:5120'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function preparePreregistrationPageSettings(): void
|
||||
{
|
||||
$ticketshop = $this->input('ticketshop_url');
|
||||
$ticketshopNormalized = null;
|
||||
@@ -37,10 +55,39 @@ trait ValidatesPreregistrationPageInput
|
||||
$ticketshopNormalized = trim($ticketshop);
|
||||
}
|
||||
|
||||
$redirect = $this->input('post_submit_redirect_url');
|
||||
$redirectNormalized = null;
|
||||
if (is_string($redirect) && trim($redirect) !== '') {
|
||||
$redirectNormalized = trim($redirect);
|
||||
}
|
||||
|
||||
$opacity = $this->input('background_overlay_opacity');
|
||||
$opacityInt = null;
|
||||
if ($opacity !== null && $opacity !== '') {
|
||||
$opacityInt = max(0, min(100, (int) $opacity));
|
||||
}
|
||||
|
||||
$this->merge([
|
||||
'phone_enabled' => $this->boolean('phone_enabled'),
|
||||
'is_active' => $this->boolean('is_active'),
|
||||
'remove_page_background' => $this->boolean('remove_page_background'),
|
||||
'ticketshop_url' => $ticketshopNormalized,
|
||||
'post_submit_redirect_url' => $redirectNormalized,
|
||||
'background_overlay_opacity' => $opacityInt,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use preregistrationPageSettingsRules
|
||||
*
|
||||
* @return array<string, array<int, ValidationRule|string>>
|
||||
*/
|
||||
protected function preregistrationPageRules(): array
|
||||
{
|
||||
return array_merge($this->preregistrationPageSettingsRules(), $this->preregistrationPageBlocksRules());
|
||||
}
|
||||
|
||||
protected function preparePreregistrationPageFields(): void
|
||||
{
|
||||
$this->preparePreregistrationPageSettings();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user