feat(custom-fields) : expose context custom fields in machine structure response

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-03 10:51:40 +02:00
parent 1385d7768c
commit da12955b52

View File

@@ -606,13 +606,14 @@ class MachineStructureController extends AbstractController
continue; continue;
} }
$items[] = [ $items[] = [
'id' => $customField->getId(), 'id' => $customField->getId(),
'name' => $customField->getName(), 'name' => $customField->getName(),
'type' => $customField->getType(), 'type' => $customField->getType(),
'required' => $customField->isRequired(), 'required' => $customField->isRequired(),
'options' => $customField->getOptions(), 'options' => $customField->getOptions(),
'defaultValue' => $customField->getDefaultValue(), 'defaultValue' => $customField->getDefaultValue(),
'orderIndex' => $customField->getOrderIndex(), 'orderIndex' => $customField->getOrderIndex(),
'machineContextOnly' => $customField->isMachineContextOnly(),
]; ];
} }
@@ -625,22 +626,25 @@ class MachineStructureController extends AbstractController
$composant = $link->getComposant(); $composant = $link->getComposant();
$modelType = $link->getModelType(); $modelType = $link->getModelType();
$parentLink = $link->getParentLink(); $parentLink = $link->getParentLink();
$type = $composant?->getTypeComposant();
return [ return [
'id' => $link->getId(), 'id' => $link->getId(),
'linkId' => $link->getId(), 'linkId' => $link->getId(),
'machineId' => $link->getMachine()->getId(), 'machineId' => $link->getMachine()->getId(),
'composantId' => $composant?->getId(), 'composantId' => $composant?->getId(),
'composant' => $composant ? $this->normalizeComposant($composant) : null, 'composant' => $composant ? $this->normalizeComposant($composant) : null,
'modelTypeId' => $modelType?->getId(), 'modelTypeId' => $modelType?->getId(),
'modelType' => $modelType ? $this->normalizeModelType($modelType) : null, 'modelType' => $modelType ? $this->normalizeModelType($modelType) : null,
'pendingEntity' => null === $composant, 'pendingEntity' => null === $composant,
'parentLinkId' => $parentLink?->getId(), 'parentLinkId' => $parentLink?->getId(),
'parentComponentLinkId' => $parentLink?->getId(), 'parentComponentLinkId' => $parentLink?->getId(),
'parentComponentId' => $parentLink?->getComposant()?->getId(), 'parentComponentId' => $parentLink?->getComposant()?->getId(),
'overrides' => $this->normalizeOverrides($link), 'overrides' => $this->normalizeOverrides($link),
'childLinks' => [], 'childLinks' => [],
'pieceLinks' => [], 'pieceLinks' => [],
'contextCustomFields' => $type ? $this->normalizeContextCustomFieldDefinitions($type->getComponentCustomFields()) : [],
'contextCustomFieldValues' => $this->normalizeCustomFieldValues($link->getContextFieldValues()),
]; ];
}, $links); }, $links);
} }
@@ -651,21 +655,24 @@ class MachineStructureController extends AbstractController
$piece = $link->getPiece(); $piece = $link->getPiece();
$modelType = $link->getModelType(); $modelType = $link->getModelType();
$parentLink = $link->getParentLink(); $parentLink = $link->getParentLink();
$type = $piece?->getTypePiece();
return [ return [
'id' => $link->getId(), 'id' => $link->getId(),
'linkId' => $link->getId(), 'linkId' => $link->getId(),
'machineId' => $link->getMachine()->getId(), 'machineId' => $link->getMachine()->getId(),
'pieceId' => $piece?->getId(), 'pieceId' => $piece?->getId(),
'piece' => $piece ? $this->normalizePiece($piece) : null, 'piece' => $piece ? $this->normalizePiece($piece) : null,
'modelTypeId' => $modelType?->getId(), 'modelTypeId' => $modelType?->getId(),
'modelType' => $modelType ? $this->normalizeModelType($modelType) : null, 'modelType' => $modelType ? $this->normalizeModelType($modelType) : null,
'pendingEntity' => null === $piece, 'pendingEntity' => null === $piece,
'parentLinkId' => $parentLink?->getId(), 'parentLinkId' => $parentLink?->getId(),
'parentComponentLinkId' => $parentLink?->getId(), 'parentComponentLinkId' => $parentLink?->getId(),
'parentComponentId' => $parentLink?->getComposant()?->getId(), 'parentComponentId' => $parentLink?->getComposant()?->getId(),
'overrides' => $this->normalizeOverrides($link), 'overrides' => $this->normalizeOverrides($link),
'quantity' => $piece ? $this->resolvePieceQuantity($link) : 1, 'quantity' => $piece ? $this->resolvePieceQuantity($link) : 1,
'contextCustomFields' => $type ? $this->normalizeContextCustomFieldDefinitions($type->getPieceCustomFields()) : [],
'contextCustomFieldValues' => $this->normalizeCustomFieldValues($link->getContextFieldValues()),
]; ];
}, $links); }, $links);
} }
@@ -859,13 +866,14 @@ class MachineStructureController extends AbstractController
continue; continue;
} }
$items[] = [ $items[] = [
'id' => $cf->getId(), 'id' => $cf->getId(),
'name' => $cf->getName(), 'name' => $cf->getName(),
'type' => $cf->getType(), 'type' => $cf->getType(),
'required' => $cf->isRequired(), 'required' => $cf->isRequired(),
'options' => $cf->getOptions(), 'options' => $cf->getOptions(),
'defaultValue' => $cf->getDefaultValue(), 'defaultValue' => $cf->getDefaultValue(),
'orderIndex' => $cf->getOrderIndex(), 'orderIndex' => $cf->getOrderIndex(),
'machineContextOnly' => $cf->isMachineContextOnly(),
]; ];
} }
@@ -886,13 +894,14 @@ class MachineStructureController extends AbstractController
'id' => $cfv->getId(), 'id' => $cfv->getId(),
'value' => $cfv->getValue(), 'value' => $cfv->getValue(),
'customField' => [ 'customField' => [
'id' => $cf->getId(), 'id' => $cf->getId(),
'name' => $cf->getName(), 'name' => $cf->getName(),
'type' => $cf->getType(), 'type' => $cf->getType(),
'required' => $cf->isRequired(), 'required' => $cf->isRequired(),
'options' => $cf->getOptions(), 'options' => $cf->getOptions(),
'defaultValue' => $cf->getDefaultValue(), 'defaultValue' => $cf->getDefaultValue(),
'orderIndex' => $cf->getOrderIndex(), 'orderIndex' => $cf->getOrderIndex(),
'machineContextOnly' => $cf->isMachineContextOnly(),
], ],
]; ];
} }
@@ -900,6 +909,30 @@ class MachineStructureController extends AbstractController
return $items; return $items;
} }
private function normalizeContextCustomFieldDefinitions(Collection $customFields): array
{
$items = [];
foreach ($customFields as $cf) {
if (!$cf instanceof CustomField || !$cf->isMachineContextOnly()) {
continue;
}
$items[] = [
'id' => $cf->getId(),
'name' => $cf->getName(),
'type' => $cf->getType(),
'required' => $cf->isRequired(),
'options' => $cf->getOptions(),
'defaultValue' => $cf->getDefaultValue(),
'orderIndex' => $cf->getOrderIndex(),
'machineContextOnly' => true,
];
}
usort($items, static fn (array $a, array $b) => $a['orderIndex'] <=> $b['orderIndex']);
return $items;
}
private function normalizeOverrides(object $link): ?array private function normalizeOverrides(object $link): ?array
{ {
$name = method_exists($link, 'getNameOverride') ? $link->getNameOverride() : null; $name = method_exists($link, 'getNameOverride') ? $link->getNameOverride() : null;