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:
@@ -613,6 +613,7 @@ class MachineStructureController extends AbstractController
|
||||
'options' => $customField->getOptions(),
|
||||
'defaultValue' => $customField->getDefaultValue(),
|
||||
'orderIndex' => $customField->getOrderIndex(),
|
||||
'machineContextOnly' => $customField->isMachineContextOnly(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -625,6 +626,7 @@ class MachineStructureController extends AbstractController
|
||||
$composant = $link->getComposant();
|
||||
$modelType = $link->getModelType();
|
||||
$parentLink = $link->getParentLink();
|
||||
$type = $composant?->getTypeComposant();
|
||||
|
||||
return [
|
||||
'id' => $link->getId(),
|
||||
@@ -641,6 +643,8 @@ class MachineStructureController extends AbstractController
|
||||
'overrides' => $this->normalizeOverrides($link),
|
||||
'childLinks' => [],
|
||||
'pieceLinks' => [],
|
||||
'contextCustomFields' => $type ? $this->normalizeContextCustomFieldDefinitions($type->getComponentCustomFields()) : [],
|
||||
'contextCustomFieldValues' => $this->normalizeCustomFieldValues($link->getContextFieldValues()),
|
||||
];
|
||||
}, $links);
|
||||
}
|
||||
@@ -651,6 +655,7 @@ class MachineStructureController extends AbstractController
|
||||
$piece = $link->getPiece();
|
||||
$modelType = $link->getModelType();
|
||||
$parentLink = $link->getParentLink();
|
||||
$type = $piece?->getTypePiece();
|
||||
|
||||
return [
|
||||
'id' => $link->getId(),
|
||||
@@ -666,6 +671,8 @@ class MachineStructureController extends AbstractController
|
||||
'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);
|
||||
}
|
||||
@@ -866,6 +873,7 @@ class MachineStructureController extends AbstractController
|
||||
'options' => $cf->getOptions(),
|
||||
'defaultValue' => $cf->getDefaultValue(),
|
||||
'orderIndex' => $cf->getOrderIndex(),
|
||||
'machineContextOnly' => $cf->isMachineContextOnly(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -893,6 +901,7 @@ class MachineStructureController extends AbstractController
|
||||
'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;
|
||||
|
||||
Reference in New Issue
Block a user