Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Check if blocks are iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-ro committed Jun 4, 2024
1 parent 05ccc6a commit dd80709
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
24 changes: 13 additions & 11 deletions resources/views/components/page-blocks.blade.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
@props(['blocks' => []])

@foreach ($blocks as $blockData)
@php
$pageBlock = \MartinRo\FilamentPageBlocks\Facades\FilamentPageBlocks::getPageBlockFromName($blockData['type'])
@endphp
@if(is_array($blocks))
@foreach ($blocks as $blockData)
@php
$pageBlock = \MartinRo\FilamentPageBlocks\Facades\FilamentPageBlocks::getPageBlockFromName($blockData['type'])
@endphp

@isset($pageBlock)
<x-dynamic-component
:component="$pageBlock::getComponent()"
:attributes="new \Illuminate\View\ComponentAttributeBag($pageBlock::mutateData($blockData['data']))"
/>
@endisset
@endforeach
@isset($pageBlock)
<x-dynamic-component
:component="$pageBlock::getComponent()"
:attributes="new \Illuminate\View\ComponentAttributeBag($pageBlock::mutateData($blockData['data']))"
/>
@endisset
@endforeach
@endif
2 changes: 1 addition & 1 deletion src/Commands/MakePageBlockCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function handle(): int

$this->copyStubToApp('PageBlock', $path, [
'class' => $pageBlockClass,
'namespace' => 'App\\Filament\\PageBlocks' . ($pageBlockNamespace !== '' ? "\\{$pageBlockNamespace}" : ''),
'namespace' => 'App\\Filament\\PageBlocks'.($pageBlockNamespace !== '' ? "\\{$pageBlockNamespace}" : ''),
'label' => $label,
'shortName' => $shortName,
]);
Expand Down
2 changes: 1 addition & 1 deletion src/FilamentPageBlocksManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function register(string $class, string $baseClass): void
public function registerPageBlock(string $pageBlock): void
{
if (! is_subclass_of($pageBlock, PageBlock::class)) {
throw new InvalidArgumentException("{$pageBlock} must extend " . PageBlock::class);
throw new InvalidArgumentException("{$pageBlock} must extend ".PageBlock::class);
}

$this->pageBlocks->put($pageBlock::getName(), $pageBlock);
Expand Down
2 changes: 1 addition & 1 deletion src/FilamentPageBlocksServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function registerComponentsFromDirectory(string $baseClass, array $reg
collect($filesystem->allFiles($directory))
->map(function (SplFileInfo $file) use ($namespace): string {
$variableNamespace = $namespace->contains('*') ? str_ireplace(
['\\' . $namespace->before('*'), $namespace->after('*')],
['\\'.$namespace->before('*'), $namespace->after('*')],
['', ''],
Str::of($file->getPath())
->after(base_path())
Expand Down
2 changes: 1 addition & 1 deletion src/PageBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function getComponent(): string
return static::$component;
}

return 'page-blocks.' . static::getName();
return 'page-blocks.'.static::getName();
}

public static function getName(): string
Expand Down

0 comments on commit dd80709

Please sign in to comment.