MishkaCmsCoreWeb.Forms.SnippetSubmit (Mishka CMS Core v0.0.1)

Copy Markdown View Source

The submit handler for the Studio's "Save as snippet" box.

It exists for one reason: to keep a failed save VISIBLE. Gervaz reports a rejected submit by assigning the errors onto the form's own state for the template to draw, and this template draws none — the box has no error slot in the design, and never had one, because every snippet failure has always been a flash. Without this, an author clicking Save on a duplicate name would watch nothing happen.

Everything else is MishkaGervaz.Form.Web.Events.SubmitHandler.Default's work; this only looks at what the state holds afterwards and forwards the first real message to the LiveView, which owns the flash. self() is the LiveView process — a LiveComponent runs inside its parent — so a plain send/2 reaches MishkaCmsCoreWeb.Live.Admin.Builder.BuilderLive.handle_info/2.

The blank-name and unparseable-markup cases never reach here: MishkaCmsCore.Runtime.Snippet's before_save hook halts on those first, so they keep the panel's own wording.

Summary

Functions

Handle post-save logic.

Submit the form for create or update.

Transform params before submission.

Functions

after_save(state, result, socket)

Handle post-save logic.

Sends {:form_saved, mode, record} to the parent LiveView and runs the after_save JS hook. An update save on a form mounted with a record_id assign reloads the saved record for editing; every other save returns the form to an empty create form.

consume_and_merge_uploads(state, form_params, socket)

@spec consume_and_merge_uploads(
  MishkaGervaz.Form.Web.State.t(),
  map(),
  Phoenix.LiveView.Socket.t()
) ::
  {Phoenix.LiveView.Socket.t(), map()}

submit(state, params, socket)

Submit the form for create or update.

Submits the AshPhoenix.Form and handles success/error. Consumes uploaded files and merges them into params before submission.

transform_params(state, params)

@spec transform_params(MishkaGervaz.Form.Web.State.t(), map()) :: map()

Transform params before submission.

Override this to add computed fields, strip unwanted params, etc.