Total Complexity | 3 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
6 | trait Renderable |
||
7 | { |
||
8 | /** |
||
9 | * Returns an array of possible views for rendering this Block’s content with |
||
10 | * It checks the URL of the current request and matches this to the folder |
||
11 | * structure of the views |
||
12 | * |
||
13 | * @return array |
||
14 | * @throws \Illuminate\Contracts\Container\BindingResolutionException |
||
15 | */ |
||
16 | protected function views() { |
||
17 | $views = []; |
||
18 | |||
19 | $views[] = config('storyblok.view_path') . 'blocks.uuid.' . $this->_uid; |
||
20 | $segments = explode('/', rtrim(app()->make('Page')->slug(), '/')); |
||
21 | // creates an array of dot paths for each path segment |
||
22 | // site.com/this/that/them becomes: |
||
23 | // this.that.them |
||
24 | // this.that |
||
25 | // this |
||
26 | $views[] = config('storyblok.view_path') . 'blocks.' . implode('.', $segments) . '.=' . $this->component; |
||
27 | $views[] = config('storyblok.view_path') . 'blocks.' . implode('.', $segments) . '.' . $this->component; |
||
28 | while (count($segments) > 1) { |
||
29 | array_pop($segments); |
||
30 | $views[] = config('storyblok.view_path') . 'blocks.' . implode('.', $segments) . '.' . $this->component; |
||
31 | } |
||
32 | |||
33 | $views[] = config('storyblok.view_path') . 'blocks.' . $this->component; |
||
34 | $views[] = config('storyblok.view_path') . 'blocks.default'; |
||
35 | |||
36 | return $views; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Finds the view used to display this block’s content |
||
41 | * it will always fall back to a default view. |
||
42 | * |
||
43 | */ |
||
44 | public function render() |
||
50 | ] |
||
51 | ); |
||
53 | } |