| Total Complexity | 5 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | trait HasBlocks |
||
| 8 | { |
||
| 9 | public function blocks() |
||
| 12 | } |
||
| 13 | |||
| 14 | public function renderBlocks($renderChilds = true, $blockViewMappings = [], $data = []) |
||
| 15 | { |
||
| 16 | return $this->blocks->where('parent_id', null)->map(function ($block) use ($blockViewMappings, $renderChilds, $data) { |
||
| 17 | if ($renderChilds) { |
||
| 18 | $childBlocks = $this->blocks->where('parent_id', $block->id); |
||
| 19 | |||
| 20 | $renderedChildViews = $childBlocks->map(function ($childBlock) use ($blockViewMappings, $data) { |
||
| 21 | $view = $this->getBlockView($childBlock->type, $blockViewMappings); |
||
| 22 | return view($view, $data)->with('block', $childBlock)->render(); |
||
| 23 | })->implode(''); |
||
| 24 | } |
||
| 25 | |||
| 26 | $block->childs = $this->blocks->where('parent_id', $block->id); |
||
| 27 | |||
| 28 | $view = $this->getBlockView($block->type, $blockViewMappings); |
||
| 29 | |||
| 30 | return view($view, $data)->with('block', $block)->render() . ($renderedChildViews ?? ''); |
||
| 31 | })->implode(''); |
||
| 32 | } |
||
| 33 | |||
| 34 | private function getBlockView($blockType, $blockViewMappings = []) |
||
| 43 | } |
||
| 44 | } |
||
| 45 |