Files
crewli/api/app/FormBuilder/Publishing/SchemaHasLinkedEvent.php
bert.hausmans 81a8120f98 feat(form-builder): add PublishGuard framework + 9 concrete guards (WS-6)
Per-purpose schema validation composes a PurposeGuardProvider returning
a list of guards. Errors collected (not first-fail) so the builder UI
surfaces every issue per save. ConditionalRequirement composes higher-
order without proliferating one-off classes.

RequiresIdentityKeyBinding checks the is_identity_key flag specifically;
the binding-existence check is handled additively by the existing
assertRequiredBindingsPresent in FormSchemaService.

SchemaHasLinkedEvent checks owner_type='event' + owner_id (FormSchema
uses polymorphic owner; there is no direct event_id column).

i18n messages live in lang/nl/form_builder_publish_guards.php.

Refs: RFC-WS-6.md §3 (Q13), §4 (V1, V3)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 22:55:42 +02:00

34 lines
956 B
PHP

<?php
declare(strict_types=1);
namespace App\FormBuilder\Publishing;
use App\Models\FormBuilder\FormSchema;
/**
* RFC-WS-6 §3 (Q13) — schema is bound to an event. FormSchema uses a
* polymorphic owner (owner_type/owner_id); this guard accepts only
* `owner_type === 'event'` with a non-null owner_id. Used as the
* sub-guard of ConditionalRequirement when AVAILABILITY_PICKER is present.
*/
final class SchemaHasLinkedEvent implements PublishGuard
{
public function code(): string
{
return 'schema_has_linked_event';
}
public function evaluate(FormSchema $schema): PublishGuardResult
{
if ($schema->owner_type === 'event' && $schema->owner_id !== null) {
return PublishGuardResult::passed($this->code());
}
return PublishGuardResult::failed(
guardCode: $this->code(),
messageKey: 'form_builder_publish_guards.schema_has_linked_event',
);
}
}