2828
2929use 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+
3138trait ContentFormTrait
3239{
40+ use HasContentFormActions;
41+
3342 protected ?string $ publishOperation = null ;
3443
44+ /**
45+ * Called by Filament's cacheTraitActions() during bootedInteractsWithActions(),
46+ * BEFORE cacheMountedActions() resolves the mounted action. This ensures the
47+ * extra status form actions are in cachedActions in time for resolution.
48+ */
49+ public function cacheHasContentFormActions (): void
50+ {
51+ foreach (inspirecms_content_statuses ()->getFormActions () as $ action ) {
52+ $ this ->cacheAction ($ action );
53+ }
54+ }
55+
3556 public function bootedContentFormTrait (): void
3657 {
3758 $ mainActions = [
@@ -537,7 +558,7 @@ protected function wrapPublisableSavingEventIntoDbTransaction(Closure $callback)
537558
538559 // region Actions
539560
540- protected function publishAction ()
561+ protected function publishAction (): Action
541562 {
542563 return Action::make ('publish ' )
543564 ->label (__ ('inspirecms::buttons.publish.label ' ))
@@ -548,21 +569,22 @@ protected function publishAction()
548569 ->color ('primary ' )
549570 ->button ()
550571 ->schema (fn (Schema $ schema ) => PublishContentForm::configure ($ schema ))
551- ->beforeFormValidated (function () {
572+ ->fillForm (fn () => ['published_at ' => now ()])
573+ ->beforeFormFilled (function (Action $ action ) {
552574 try {
553-
554575 $ this ->validatePublishableData ();
555-
556- } catch (Throwable $ e ) {
576+ } catch (ValidationException $ e ) {
557577 Notification::make ()
558578 ->title (__ ('inspirecms::notification.form_check_error.title ' ))
559579 ->danger ()
560580 ->send ();
561581
562- throw $ e ;
582+ $ action -> halt () ;
563583 }
564584 })
565- ->action (fn ($ data , $ action ) => $ this ->publish ($ data , $ action ))
585+ ->action (function (array $ data , Action $ action ) {
586+ $ this ->publish ($ data , $ action );
587+ })
566588 ->model (InspireCmsConfig::getContentModelClass ())
567589 ->authorize ('publish ' )
568590 // Cannot publish if the parent is not published
@@ -584,7 +606,7 @@ protected function publishAction()
584606 });
585607 }
586608
587- protected function publishDescendantsAndSelfAction ()
609+ protected function publishDescendantsAndSelfAction (): Action
588610 {
589611 return $ this ->publishAction ()
590612 ->name ('publishDescendantsAndSelf ' )
0 commit comments