Skip to content

Commit

Permalink
Backport repeaters implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
haringsrob committed Mar 15, 2022
1 parent 10fa96f commit aeb6dae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Models/Behaviors/HasBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions src/Services/Blocks/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit aeb6dae

Please sign in to comment.