refactor(form-builder): pre-publish check reads form_field_bindings; drop binding JSON columns
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Exceptions\FormBuilder\EditLockConflictException;
|
||||
use App\Exceptions\FormBuilder\PurposeRequirementsNotMetException;
|
||||
use App\FormBuilder\Purposes\PurposeRegistry;
|
||||
use App\Models\FormBuilder\FormField;
|
||||
use App\Models\FormBuilder\FormFieldBinding;
|
||||
use App\Models\FormBuilder\FormSchema;
|
||||
use App\Models\FormBuilder\FormSchemaSection;
|
||||
use App\Models\FormBuilder\FormSubmission;
|
||||
@@ -133,8 +134,8 @@ final class FormSchemaService
|
||||
* purpose is bound by at least one field on the schema.
|
||||
*
|
||||
* Binding paths follow Pattern A notation (`{entity}.{attribute}`).
|
||||
* In v1.0 we read `form_fields.binding` JSON; WS-5a will switch this
|
||||
* to the relational `form_field_bindings` table.
|
||||
* Sourced from the relational `form_field_bindings` table (WS-5a;
|
||||
* ARCH §6.7, §17.3).
|
||||
*/
|
||||
private function assertRequiredBindingsPresent(FormSchema $schema): void
|
||||
{
|
||||
@@ -151,19 +152,16 @@ final class FormSchemaService
|
||||
return;
|
||||
}
|
||||
|
||||
$bound = [];
|
||||
foreach ($schema->fields as $field) {
|
||||
$binding = $field->binding;
|
||||
if (! is_array($binding)) {
|
||||
continue;
|
||||
}
|
||||
$entity = (string) ($binding['entity'] ?? '');
|
||||
$column = (string) ($binding['column'] ?? '');
|
||||
if ($entity === '' || $column === '') {
|
||||
continue;
|
||||
}
|
||||
$bound[] = $entity.'.'.$column;
|
||||
}
|
||||
$fieldIds = $schema->fields()->pluck('id');
|
||||
|
||||
$bound = FormFieldBinding::query()
|
||||
->withoutGlobalScopes()
|
||||
->where('owner_type', 'form_field')
|
||||
->whereIn('owner_id', $fieldIds)
|
||||
->get(['target_entity', 'target_attribute'])
|
||||
->map(fn (FormFieldBinding $b) => $b->target_entity.'.'.$b->target_attribute)
|
||||
->unique()
|
||||
->all();
|
||||
|
||||
$missing = array_values(array_diff($required, $bound));
|
||||
if ($missing !== []) {
|
||||
|
||||
Reference in New Issue
Block a user