66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UpdatePreregistrationPageRequest extends FormRequest
|
|
{
|
|
use ValidatesPreregistrationPageInput;
|
|
|
|
public function authorize(): bool
|
|
{
|
|
$page = $this->route('page');
|
|
if ($page === null) {
|
|
return false;
|
|
}
|
|
|
|
return $this->user()?->can('update', $page) ?? false;
|
|
}
|
|
|
|
protected function prepareForValidation(): void
|
|
{
|
|
$this->preparePreregistrationPageSettings();
|
|
$blocks = $this->input('blocks');
|
|
if (! is_array($blocks)) {
|
|
return;
|
|
}
|
|
$merged = [];
|
|
foreach ($blocks as $key => $row) {
|
|
if (! is_array($row)) {
|
|
continue;
|
|
}
|
|
$row['is_visible'] = filter_var($row['is_visible'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
|
$row['remove_block_image'] = filter_var($row['remove_block_image'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
|
$merged[$key] = $row;
|
|
}
|
|
$this->merge(['blocks' => $merged]);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array<int, ValidationRule|string>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return array_merge(
|
|
$this->preregistrationPageSettingsRules(),
|
|
$this->preregistrationPageBlocksRules(),
|
|
);
|
|
}
|
|
|
|
public function withValidator(Validator $validator): void
|
|
{
|
|
$validator->after(function (Validator $validator): void {
|
|
$blocks = $this->input('blocks');
|
|
if (! is_array($blocks)) {
|
|
return;
|
|
}
|
|
PageBlockContentValidator::validateBlocksArray($validator, $blocks);
|
|
});
|
|
}
|
|
}
|