fix(custom-fields) : persist machineContextOnly in structure save and clone

- SkeletonStructureService: read and write machineContextOnly on create/update
- normalizeCustomFieldData: pass machineContextOnly through both payload formats
- cloneCustomFields: copy machineContextOnly flag on machine clone

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-03 13:09:15 +02:00
parent 61584f2f9b
commit a88e4a68fb
2 changed files with 18 additions and 13 deletions

View File

@@ -191,6 +191,7 @@ class MachineStructureController extends AbstractController
$newCf->setDefaultValue($cf->getDefaultValue());
$newCf->setOptions($cf->getOptions());
$newCf->setOrderIndex($cf->getOrderIndex());
$newCf->setMachineContextOnly($cf->isMachineContextOnly());
$newCf->setMachine($target);
$this->entityManager->persist($newCf);

View File

@@ -233,6 +233,7 @@ class SkeletonStructureService
$existingField->setOptions($normalized['options']);
$existingField->setDefaultValue($normalized['defaultValue']);
$existingField->setOrderIndex($normalized['orderIndex']);
$existingField->setMachineContextOnly($normalized['machineContextOnly']);
$processedIds[$existingField->getId()] = true;
} else {
// Create new field
@@ -243,6 +244,7 @@ class SkeletonStructureService
$cf->setOptions($normalized['options']);
$cf->setDefaultValue($normalized['defaultValue']);
$cf->setOrderIndex($normalized['orderIndex']);
$cf->setMachineContextOnly($normalized['machineContextOnly']);
match ($category) {
ModelCategory::COMPONENT => $cf->setTypeComposant($modelType),
@@ -265,7 +267,7 @@ class SkeletonStructureService
/**
* Normalize frontend custom field data to a common shape.
*
* @return array{name: string, type: string, required: bool, options: ?array, defaultValue: ?string, orderIndex: int}
* @return array{name: string, type: string, required: bool, options: ?array, defaultValue: ?string, orderIndex: int, machineContextOnly: bool}
*/
private function normalizeCustomFieldData(array $fieldData, int $index): array
{
@@ -274,23 +276,25 @@ class SkeletonStructureService
$value = $fieldData['value'];
return [
'name' => $fieldData['key'],
'type' => $value['type'] ?? 'text',
'required' => (bool) ($value['required'] ?? false),
'options' => $value['options'] ?? null,
'defaultValue' => $value['defaultValue'] ?? null,
'orderIndex' => $index,
'name' => $fieldData['key'],
'type' => $value['type'] ?? 'text',
'required' => (bool) ($value['required'] ?? false),
'options' => $value['options'] ?? null,
'defaultValue' => $value['defaultValue'] ?? null,
'orderIndex' => $index,
'machineContextOnly' => (bool) ($value['machineContextOnly'] ?? false),
];
}
// PIECE/PRODUCT format: {name, type, required, options?, orderIndex?, defaultValue?}
return [
'name' => $fieldData['name'] ?? '',
'type' => $fieldData['type'] ?? 'text',
'required' => (bool) ($fieldData['required'] ?? false),
'options' => $fieldData['options'] ?? null,
'defaultValue' => $fieldData['defaultValue'] ?? null,
'orderIndex' => $fieldData['orderIndex'] ?? $index,
'name' => $fieldData['name'] ?? '',
'type' => $fieldData['type'] ?? 'text',
'required' => (bool) ($fieldData['required'] ?? false),
'options' => $fieldData['options'] ?? null,
'defaultValue' => $fieldData['defaultValue'] ?? null,
'orderIndex' => $fieldData['orderIndex'] ?? $index,
'machineContextOnly' => (bool) ($fieldData['machineContextOnly'] ?? false),
];
}
}