Skip to content

Commit

Permalink
Merge commit '84631a5166a71ff9404f3104c7bcb3ff9b9cd2ff' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
marco76tv committed Jun 3, 2024
2 parents f763f4b + 84631a5 commit c6857ec
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Filament/Blocks/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function make(
->columnSpanFull(),
]
)
->columns('form' === $context ? 2 : 1);
->columns($context === 'form' ? 2 : 1);
}

public static function getRatios(): array
Expand Down
69 changes: 69 additions & 0 deletions Filament/Blocks/ImageSpatie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace Modules\UI\Filament\Blocks;

use Filament\Forms;
use Filament\Forms\Components\Builder\Block;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\TextInput;
use Illuminate\Support\Str;

class ImageSpatie
{
public static function make(
string $name = 'image_spatie',
string $context = 'form',
): Block {
return Block::make($name)
->schema([
Forms\Components\Hidden::make('img_uuid')
->default(fn () => Str::uuid()->toString())
->formatStateUsing(fn ($state) => $state ?? Str::uuid()->toString())
->live(),
// ->required(),

SpatieMediaLibraryFileUpload::make('image')
->columnSpanFull()
->collection(fn (Forms\Get $get) => $get('img_uuid')),

Select::make('ratio')
->options(static::getRatios())
->afterStateHydrated(static fn ($state, $set) => $state || $set('ratio', '4-3')),

TextInput::make('alt')
->columnSpanFull(),

TextInput::make('caption')
->columnSpanFull(),

// Filament\Forms\Components\SpatieMediaLibraryFileUpload::whereCustomProperties does not exist.
// ->whereCustomProperties(fn(Forms\Get $get) => ['gallery_id' => $get('gallery_id')])

// ->customProperties(fn(Forms\Get $get) => ['gallery_id' => $get('gallery_id')]),

// Forms\Components\SpatieMediaLibraryFileUpload::make('media_id')
])
->columns($context === 'form' ? 2 : 1);
}

public static function getRatios(): array
{
return [
'4-3' => '4/3',
'3-4' => '3/4',
'free' => 'free',
];
}

public static function getRatioClass(string $ratio): string
{
return match ($ratio) {
'4-3' => 'aspect-[4/3]',
'3-4' => 'aspect-[3/4]',
default => '',
};
}
}
2 changes: 1 addition & 1 deletion Filament/Blocks/Slider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public static function make(
// ->afterStateHydrated(static fn ($state, $set) => $state || $set('level', 'h2')),
]
)
->columns('form' === $context ? 2 : 1);
->columns($context === 'form' ? 2 : 1);
}
}
2 changes: 1 addition & 1 deletion Filament/Blocks/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public static function make(
->options($views),
]
)
->columns('form' === $context ? 2 : 1);
->columns($context === 'form' ? 2 : 1);
}
}
4 changes: 2 additions & 2 deletions Filament/Forms/Components/AddressField.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function saveRelationships(): void
$record = $this->getRecord();
$relationship = $record?->{$this->getRelationship()}();

if (null === $relationship) {
if ($relationship === null) {
return;
} elseif ($address = $relationship->first()) {
$address->update($state);
Expand Down Expand Up @@ -80,7 +80,7 @@ protected function setUp(): void
'zip' => null,
];
$address = $record?->getRelationValue($this->getRelationship());
if (null != $address && is_object($address) && method_exists($address, 'toArray')) {
if ($address != null && is_object($address) && method_exists($address, 'toArray')) {
$data = $address->toArray();
}

Expand Down
6 changes: 3 additions & 3 deletions View/Components/Render/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public function render(): ViewFactory|View
return view('ui::empty');
}

if ('v1' === $this->tpl) {
if ($this->tpl === 'v1') {
$this->tpl = $this->block['type'];
} else {
$this->tpl = $this->block['type'].'.'.$this->tpl;
}

$views = ['ui::components.blocks.'.$this->tpl];
if (null !== $this->model) {
if ($this->model !== null) {
$module = app(GetModuleNameFromModelAction::class)->execute($this->model);
$views[] = strtolower($module).'::components.blocks.'.$this->tpl;
}
Expand All @@ -53,7 +53,7 @@ public function render(): ViewFactory|View
* @phpstan-var view-string|null
*/
$view = Arr::first($views, $callback);
if (null === $view) {
if ($view === null) {
throw new \Exception('none of these views exists ['.implode(', '.\chr(13), $views).']');
}
$view_params = $this->block['data'] ?? [];
Expand Down
3 changes: 1 addition & 2 deletions View/Composers/ThemeComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public function metatags(): \Illuminate\View\View
}

/**
* @param string $index
*
* @param string $index
* @return \Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed
*/
public function metatag($index)
Expand Down

0 comments on commit c6857ec

Please sign in to comment.