add element siblings
This commit is contained in:
parent
eb868679c8
commit
96774d9540
3 changed files with 47 additions and 9 deletions
|
|
@ -46,18 +46,15 @@ class ElementController
|
|||
}
|
||||
|
||||
$element = $result->getElement();
|
||||
$childElements = [];
|
||||
foreach ($result->getChildElements() as $childElement) {
|
||||
$childElements[] = [
|
||||
'id' => $childElement->getId(),
|
||||
'title' => $childElement->getTitle(),
|
||||
'description' => $childElement->getDescription(),
|
||||
];
|
||||
}
|
||||
|
||||
return new JsonResponse([
|
||||
'childElements' => $childElements,
|
||||
'childElements' => $this->buildElementSummaryPayloads(
|
||||
$result->getChildElements(),
|
||||
),
|
||||
'element' => $this->buildElementPayload($element),
|
||||
'siblingElements' => $this->buildElementSummaryPayloads(
|
||||
$result->getSiblingElements(),
|
||||
),
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
|
@ -253,6 +250,28 @@ class ElementController
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Element[] $elements
|
||||
* @return array<int, array{
|
||||
* id: int,
|
||||
* title: string,
|
||||
* description: string,
|
||||
* }>
|
||||
*/
|
||||
private function buildElementSummaryPayloads(array $elements): array
|
||||
{
|
||||
$payloads = [];
|
||||
foreach ($elements as $element) {
|
||||
$payloads[] = [
|
||||
'id' => $element->getId(),
|
||||
'title' => $element->getTitle(),
|
||||
'description' => $element->getDescription(),
|
||||
];
|
||||
}
|
||||
|
||||
return $payloads;
|
||||
}
|
||||
|
||||
private function storageUrl(?string $path, string $folderPrefix): ?string
|
||||
{
|
||||
if ($path === null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue