diff --git a/src/Controller/Api/BlockController.php b/src/Controller/Api/BlockController.php new file mode 100644 index 0000000..c0dd9e8 --- /dev/null +++ b/src/Controller/Api/BlockController.php @@ -0,0 +1,28 @@ +entityRegistry = $entityRegistry; + } + + /** + * Endpoint to list all available blocks + */ + public function listBlocks(): JsonResponse + { + $this->entityRegistry->getAvailableBlockTypes(); + } + +} diff --git a/src/Controller/Api/ZoneController.php b/src/Controller/Api/ZoneController.php index c9ae88e..6ecd3e8 100644 --- a/src/Controller/Api/ZoneController.php +++ b/src/Controller/Api/ZoneController.php @@ -91,4 +91,5 @@ public function updateZone(Request $request, string $id): JsonResponse return new JsonResponse(['status' => 'Zone updated successfully']); } + } diff --git a/src/Registry/EntityRegistry.php b/src/Registry/EntityRegistry.php index 8bacbb3..b84a720 100644 --- a/src/Registry/EntityRegistry.php +++ b/src/Registry/EntityRegistry.php @@ -39,4 +39,9 @@ public function getFieldClass(string $type): ?string { return $this->fieldTypes[$type] ?? null; } + + public function getAvailableBlock(): BlockCollection + { + + } } diff --git a/src/Resources/editor/src/App.vue b/src/Resources/editor/src/App.vue index ec2263a..6b66729 100644 --- a/src/Resources/editor/src/App.vue +++ b/src/Resources/editor/src/App.vue @@ -8,9 +8,11 @@ import { buildNewBlockContentFromBlockStructure } from "./core-logic/utils/build const zoneStore = useZoneStore(); onMounted(() => { + // @todo: get the content from the server instead of using the test data const columnContent = buildNewBlockContentFromBlockStructure(columnStructure); const allFieldsContent = buildNewBlockContentFromBlockStructure(allFieldsStructure); + zoneStore.$patch({ availableBlocks: [columnStructure, allFieldsStructure], content: [columnContent, allFieldsContent], diff --git a/src/Service/ZoneService.php b/src/Service/ZoneService.php index 28b2db4..a727327 100644 --- a/src/Service/ZoneService.php +++ b/src/Service/ZoneService.php @@ -4,13 +4,10 @@ namespace PrestaSafe\PrettyBlocks\Service; -use PrestaSafe\PrettyBlocks\Entity\Component\AbstractComponent; -use PrestaSafe\PrettyBlocks\Entity\PrimitiveField\AbstractPrimitiveField; -use PrestaSafe\PrettyBlocks\Entity\PrimitiveField\TextField; +use PrestaSafe\PrettyBlocks\Entity\Block\BlockInterface; use PrestaSafe\PrettyBlocks\Entity\Zone; use PrestaSafe\PrettyBlocks\Factory\EntityFactory; use PrestaSafe\PrettyBlocks\Repository\ZoneRepository; -use PrestaSafe\PrettyBlocks\Entity\Block\BlockInterface; class ZoneService { @@ -42,16 +39,22 @@ public function updateZone(Zone $zone, array $blocks): void // Add new blocks foreach ($blocks as $blockData) { - $block = $this->hydrateBlockFromData($blockData); + $block = $this->hydrateBlockFromDataStructure($blockData); $zone->addBlock($block); } $this->zoneRepository->save($zone); } - private function hydrateBlockFromData(array $data): BlockInterface + private function hydrateBlockFromDataStructure(array $data): BlockInterface { - return $this->entityFactory->createBlock($data); - } + $block = $this->entityFactory->createBlock($data); + // Hydrater les champs du bloc + foreach ($data['fields'] as $fieldData) { + $field = $this->entityFactory->createField($fieldData); + $block->addField($field); + } + return $block; + } }