Skip to content

Commit

Permalink
Allow extending of page edit record forms (#1938)
Browse files Browse the repository at this point in the history
This PR adds the ability to extend base edit record pages.

Our use case is the ability to add to the inventory pages, which is why
I've applied this to them.

---------

Co-authored-by: Author <[email protected]>
  • Loading branch information
ryanmitchell and actions-user authored Nov 19, 2024
1 parent 613e597 commit fd3008b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function getFormActions(): array
];
}

public function form(Form $form): Form
public function getDefaultForm(Form $form): Form
{
return (new ManageVariantInventory)->form($form)->statePath('');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function getDefaultHeaderActions(): array
];
}

public function form(Form $form): Form
public function getDefaultForm(Form $form): Form
{
return $form->schema([
Section::make()->schema([
Expand Down
1 change: 1 addition & 0 deletions packages/admin/src/Support/Pages/BaseCreateRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ abstract class BaseCreateRecord extends CreateRecord
{
use Concerns\ExtendsFooterWidgets;
use Concerns\ExtendsFormActions;
use Concerns\ExtendsForms;
use Concerns\ExtendsHeaderActions;
use Concerns\ExtendsHeaderWidgets;
use Concerns\ExtendsHeadings;
Expand Down
1 change: 1 addition & 0 deletions packages/admin/src/Support/Pages/BaseEditRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ abstract class BaseEditRecord extends EditRecord
{
use Concerns\ExtendsFooterWidgets;
use Concerns\ExtendsFormActions;
use Concerns\ExtendsForms;
use Concerns\ExtendsHeaderActions;
use Concerns\ExtendsHeaderWidgets;
use Concerns\ExtendsHeadings;
Expand Down
18 changes: 18 additions & 0 deletions packages/admin/src/Support/Pages/Concerns/ExtendsForms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Lunar\Admin\Support\Pages\Concerns;

use Filament\Forms\Form;

trait ExtendsForms
{
public function form(Form $form): Form
{
return self::callLunarHook('extendForm', $this->getDefaultForm($form));
}

public function getDefaultForm(Form $form): Form
{
return $form;
}
}

0 comments on commit fd3008b

Please sign in to comment.