From 95c0bac419ce023fd49b95044ced372834ff502b Mon Sep 17 00:00:00 2001 From: marco76tv Date: Mon, 5 Feb 2024 14:48:59 +0100 Subject: [PATCH] Refactor form structure in Image and Title blocks --- Filament/Blocks/Image.php | 7 +++++++ Filament/Blocks/Title.php | 12 ++++++++++++ .../Pages/Concerns/HandlesTreeBuilder.php | 16 +++++++++++++++- View/Components/Render/Block.php | 15 ++++++++++++++- 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Filament/Blocks/Image.php b/Filament/Blocks/Image.php index aab08505..d0f31ed1 100644 --- a/Filament/Blocks/Image.php +++ b/Filament/Blocks/Image.php @@ -31,11 +31,18 @@ public static function make( TextInput::make('alt') ->columnSpanFull(), +<<<<<<< HEAD TextInput::make('caption') ->columnSpanFull(), ] ) ->columns('form' === $context ? 2 : 1); +======= + TextInput::make('caption') + ->columnSpanFull(), + ]) + ->columns($context === 'form' ? 2 : 1); +>>>>>>> ef98e3f (rebase 4) } public static function getRatios(): array diff --git a/Filament/Blocks/Title.php b/Filament/Blocks/Title.php index 66826c99..074fff41 100644 --- a/Filament/Blocks/Title.php +++ b/Filament/Blocks/Title.php @@ -20,6 +20,7 @@ public static function make( TextInput::make('text') ->required(), +<<<<<<< HEAD Select::make('level') ->options( [ @@ -32,5 +33,16 @@ public static function make( ] ) ->columns('form' === $context ? 2 : 1); +======= + Select::make('level') + ->options([ + 'h2' => 'h2', + 'h3' => 'h3', + 'h4' => 'h4', + ]) + ->afterStateHydrated(static fn ($state, $set) => $state || $set('level', 'h2')), + ]) + ->columns($context === 'form' ? 2 : 1); +>>>>>>> ef98e3f (rebase 4) } } diff --git a/Filament/Resources/TreeResource/Pages/Concerns/HandlesTreeBuilder.php b/Filament/Resources/TreeResource/Pages/Concerns/HandlesTreeBuilder.php index 5cb69c1d..ed6840b5 100644 --- a/Filament/Resources/TreeResource/Pages/Concerns/HandlesTreeBuilder.php +++ b/Filament/Resources/TreeResource/Pages/Concerns/HandlesTreeBuilder.php @@ -151,6 +151,7 @@ public function storeChildItem(Model $record, array $data): void { $parent = data_get($this, $this->mountedChildTarget); $data['parent_id'] = $parent['id']; +<<<<<<< HEAD /* dddx([ 'data' => $data, @@ -161,6 +162,19 @@ public function storeChildItem(Model $record, array $data): void $new_id = app(GetNewInventoryNumberAction::class)->execute($record::class, $data['parent_id']); $data['id'] = $new_id; +======= + if (Str::contains($data['parent_id'], '-')) { + $last_son = $record::class::where('parent_id', $data['parent_id']) + ->orderByDesc('id') + ->first(); + if ($last_son == null) { + $data['id'] = $data['parent_id'].'-1'; + } else { + $new_id = intval(Str::afterLast($last_son['id'], '-')) + 1; + $data['id'] = $data['parent_id'].'-'.$new_id; + } + } +>>>>>>> ef98e3f (rebase 4) $row = $record::class::create($data); $data = $row->toArray(); $data['id'] = $new_id; @@ -224,7 +238,7 @@ function (array $data, $record): void { } ) ->requiresConfirmation() - ->visible(null != $this->mountedItem), + ->visible($this->mountedItem != null), Action::make('item') ->mountUsing( function (ComponentContainer $form): void { diff --git a/View/Components/Render/Block.php b/View/Components/Render/Block.php index ec3053c5..aa0ac64c 100644 --- a/View/Components/Render/Block.php +++ b/View/Components/Render/Block.php @@ -28,7 +28,7 @@ public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\View\Vi $this->tpl = $this->block['type']; $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; } @@ -37,8 +37,21 @@ public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\View\Vi * @phpstan-var view-string|null */ $view = Arr::first($views, static fn (string $view) => view()->exists($view)); +<<<<<<< HEAD if (null === $view) { +<<<<<<< HEAD throw new \Exception('none of these views exists ['.implode(', '.chr(13), $views).']'); +======= +<<<<<<< HEAD + throw new Exception('none of these views exists ['.implode(', '.chr(13),$views).']'); + //dddx([$views, $this->model]); +======= +======= + if ($view === null) { +>>>>>>> 1fc11df (Dusting) + dddx([$views, $this->model]); +>>>>>>> 760233f (Lint) +>>>>>>> ef98e3f (rebase 4) } $view_params = $this->block['data'] ?? [];