Skip to content

Commit

Permalink
Refactor form structure in Image and Title blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
marco76tv committed Feb 5, 2024
1 parent 3aa7153 commit 95c0bac
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Filament/Blocks/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Filament/Blocks/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static function make(
TextInput::make('text')
->required(),

<<<<<<< HEAD
Select::make('level')
->options(
[
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 14 additions & 1 deletion View/Components/Render/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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'] ?? [];

Expand Down

0 comments on commit 95c0bac

Please sign in to comment.