Skip to content

Commit 39ffaa1

Browse files
committed
Hotfix: 'Publish' action no effect
1 parent da7df0f commit 39ffaa1

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/Base/Filament/Concerns/ContentFormTrait.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,30 @@
2828

2929
use function Filament\Support\is_app_url;
3030

31+
/**
32+
* Marker trait — enables Filament's cacheTraitActions() to call
33+
* cacheHasContentFormActions() before cacheMountedActions() runs,
34+
* so extra status actions are in cachedActions in time.
35+
*/
36+
trait HasContentFormActions {}
37+
3138
trait ContentFormTrait
3239
{
40+
use HasContentFormActions;
3341
protected ?string $publishOperation = null;
3442

43+
/**
44+
* Called by Filament's cacheTraitActions() during bootedInteractsWithActions(),
45+
* BEFORE cacheMountedActions() resolves the mounted action. This ensures the
46+
* extra status form actions are in cachedActions in time for resolution.
47+
*/
48+
public function cacheHasContentFormActions(): void
49+
{
50+
foreach (inspirecms_content_statuses()->getFormActions() as $action) {
51+
$this->cacheAction($action);
52+
}
53+
}
54+
3555
public function bootedContentFormTrait(): void
3656
{
3757
$mainActions = [
@@ -537,7 +557,7 @@ protected function wrapPublisableSavingEventIntoDbTransaction(Closure $callback)
537557

538558
// region Actions
539559

540-
protected function publishAction()
560+
protected function publishAction(): Action
541561
{
542562
return Action::make('publish')
543563
->label(__('inspirecms::buttons.publish.label'))
@@ -548,21 +568,22 @@ protected function publishAction()
548568
->color('primary')
549569
->button()
550570
->schema(fn (Schema $schema) => PublishContentForm::configure($schema))
551-
->beforeFormValidated(function () {
571+
->fillForm(fn () => ['published_at' => now()])
572+
->beforeFormFilled(function (Action $action) {
552573
try {
553-
554574
$this->validatePublishableData();
555-
556-
} catch (Throwable $e) {
575+
} catch (ValidationException $e) {
557576
Notification::make()
558577
->title(__('inspirecms::notification.form_check_error.title'))
559578
->danger()
560579
->send();
561580

562-
throw $e;
581+
$action->halt();
563582
}
564583
})
565-
->action(fn ($data, $action) => $this->publish($data, $action))
584+
->action(function (array $data, Action $action) {
585+
$this->publish($data, $action);
586+
})
566587
->model(InspireCmsConfig::getContentModelClass())
567588
->authorize('publish')
568589
// Cannot publish if the parent is not published
@@ -584,7 +605,7 @@ protected function publishAction()
584605
});
585606
}
586607

587-
protected function publishDescendantsAndSelfAction()
608+
protected function publishDescendantsAndSelfAction(): Action
588609
{
589610
return $this->publishAction()
590611
->name('publishDescendantsAndSelf')

0 commit comments

Comments
 (0)