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