Skip to content

Commit

Permalink
retrieve resource namespace using filament facade / retrieve content …
Browse files Browse the repository at this point in the history
…when translation are not used in model
  • Loading branch information
michael-sevendays-be committed Oct 9, 2023
1 parent 23369d2 commit cf9350c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/BlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sevendays\FilamentPageBuilder;

use Filament\Facades\Filament;
use Illuminate\Contracts\View\View;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -32,7 +33,7 @@ public function getAllBlocks(): array
return [];
}

$namespace = Str::of(config('filament.resources.namespace'))->beforeLast('\\')->append('\\Blocks*');
$namespace = Str::of(Filament::getCurrentPanel()->getResourceNamespaces()[0])->beforeLast('\\')->append('\\Blocks*');

$classes = collect($this->filesystem->allFiles($blocksDirectory))
->map(function (SplFileInfo $file) use ($namespace) {
Expand Down Expand Up @@ -66,7 +67,12 @@ public function renderBlock(Block $block): string|View
{
/** @var class-string<BlockEditorBlock> $class */
if ($class = ($this->getAllBlocks()[$block->type] ?? false)) {

Check failure on line 69 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$type.

Check failure on line 69 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Variable $class in PHPDoc tag @var does not exist.

Check failure on line 69 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$type.

Check failure on line 69 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Variable $class in PHPDoc tag @var does not exist.
$content = is_array($block->shared) ? [...$block->content, ...$block->shared] : $block->content;
$pageContent = $block->content;

Check failure on line 70 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$content.

Check failure on line 70 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$content.
//todo dirty hack to 'detect' if translations are in use ...
if($block->content === ''){

Check failure on line 72 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$content.

Check failure on line 72 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$content.
$pageContent = $block->translations['content'];

Check failure on line 73 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$translations.

Check failure on line 73 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$translations.
}
$content = is_array($block->shared) ? [...$pageContent, ...$block->shared] : $pageContent;

Check failure on line 75 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$shared.

Check failure on line 75 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$shared.

return $class::make($block->type)->renderDisplay($content);

Check failure on line 77 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$type.

Check failure on line 77 in src/BlockRenderer.php

View workflow job for this annotation

GitHub Actions / phpstan

Access to an undefined property Sevendays\FilamentPageBuilder\Models\Block::$type.
}
Expand Down

0 comments on commit cf9350c

Please sign in to comment.