From aeb6daee5e983f1dc26463234c6cfee6525a7cd0 Mon Sep 17 00:00:00 2001 From: Harings Rob Date: Tue, 15 Mar 2022 14:41:27 +0100 Subject: [PATCH] Backport repeaters implementation. --- src/Models/Behaviors/HasBlocks.php | 4 ++-- src/Services/Blocks/Block.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Models/Behaviors/HasBlocks.php b/src/Models/Behaviors/HasBlocks.php index 2d10b9ec4..003b7a1f2 100644 --- a/src/Models/Behaviors/HasBlocks.php +++ b/src/Models/Behaviors/HasBlocks.php @@ -34,7 +34,7 @@ public function renderNamedBlocks($name = 'default', $renderChilds = true, $bloc $childBlocks = $this->blocks->where('parent_id', $block->id); $renderedChildViews = $childBlocks->map(function ($childBlock) use ($blockViewMappings, $data) { - $class = BlockConfig::getForType($childBlock->type); + $class = BlockConfig::findFirstWithType($childBlock->type); $view = $class->getBlockView($blockViewMappings); $data = $class->getData($data, $childBlock); @@ -44,7 +44,7 @@ public function renderNamedBlocks($name = 'default', $renderChilds = true, $bloc $block->childs = $this->blocks->where('parent_id', $block->id); - $class = BlockConfig::getForType($block->type); + $class = BlockConfig::findFirstWithType($block->type); $view = $class->getBlockView($blockViewMappings); $data = $class->getData($data, $block); diff --git a/src/Services/Blocks/Block.php b/src/Services/Blocks/Block.php index 368b085a0..ef2a259b6 100644 --- a/src/Services/Blocks/Block.php +++ b/src/Services/Blocks/Block.php @@ -138,6 +138,14 @@ public static function make($file, $type, $source, $name = null): self return new self($file, $type, $source, $name); } + /** + * Gets the first match being a block or repeater. + */ + public static function findFirstWithType(string $type): ?self + { + return app(BlockCollection::class)->findByName($type); + } + public static function getForType(string $type, bool $repeater = false): self { if ($repeater) {