Reduces the FormPurpose vocabulary from 22 variants + a `custom` escape to the seven v1.0 purposes registered in the new PurposeRegistry. - Purge migration deletes any form_schemas row whose `purpose` is not in the v1.0 set (cascades through form_fields, form_submissions, form_values, form_value_options, form_schema_sections, form_submission_section_statuses, form_submission_delegations, form_schema_webhooks, form_webhook_deliveries via existing FK). - Drop migration removes the `custom_purpose_slug` column + its index. - Both migrations declare their `down()` as a hard failure — we do not support reversing a purge (pre-launch, no production data). - `FormPurpose` enum slims to the seven cases; the legacy helpers (defaultSubmissionMode / defaultSubjectType / allowsPublicAccess) now delegate to PurposeRegistry so callers keep working. - FormSchema fillable / FormSchemaResource / StoreFormSchemaRequest / UpdateFormSchemaRequest / FormSchemaFactory drop every reference to `custom_purpose_slug` and the `custom` purpose. - VerifyFormsDataIntegrity drops the custom-slug mismatch check and sources the subject-type allow-list from PurposeRegistry. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Factories\FormBuilder;
|
|
|
|
use App\Enums\FormBuilder\FormPurpose;
|
|
use App\Enums\FormBuilder\FormSchemaSnapshotMode;
|
|
use App\Models\FormBuilder\FormSchema;
|
|
use App\Models\Organisation;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
/** @extends Factory<FormSchema> */
|
|
final class FormSchemaFactory extends Factory
|
|
{
|
|
protected $model = FormSchema::class;
|
|
|
|
/** @return array<string, mixed> */
|
|
public function definition(): array
|
|
{
|
|
$purpose = fake()->randomElement([
|
|
FormPurpose::EVENT_REGISTRATION,
|
|
FormPurpose::INCIDENT_REPORT,
|
|
FormPurpose::USER_PROFILE,
|
|
FormPurpose::POST_EVENT_EVALUATION,
|
|
]);
|
|
$name = 'Formulier '.fake('nl_NL')->words(2, true);
|
|
|
|
return [
|
|
'organisation_id' => Organisation::factory(),
|
|
'owner_type' => null,
|
|
'owner_id' => null,
|
|
'name' => $name,
|
|
'slug' => Str::slug($name).'-'.Str::lower(Str::random(4)),
|
|
'purpose' => $purpose,
|
|
'description' => fake('nl_NL')->sentence(),
|
|
'is_published' => false,
|
|
'submission_mode' => $purpose->defaultSubmissionMode(),
|
|
'locale' => 'nl',
|
|
'snapshot_mode' => FormSchemaSnapshotMode::NEVER,
|
|
'freeze_on_submit' => false,
|
|
'section_level_submit' => false,
|
|
'auto_save_enabled' => false,
|
|
'version' => 1,
|
|
];
|
|
}
|
|
|
|
public function published(): static
|
|
{
|
|
return $this->state(fn () => ['is_published' => true]);
|
|
}
|
|
|
|
public function forPurpose(FormPurpose $purpose): static
|
|
{
|
|
return $this->state(fn () => [
|
|
'purpose' => $purpose,
|
|
'submission_mode' => $purpose->defaultSubmissionMode(),
|
|
]);
|
|
}
|
|
}
|