# `MishkaCmsCoreWeb.Forms.SnippetSubmit`
[🔗](https://github.com/mishka-group/mishka_cms_core/blob/v0.0.1/lib/mishka_cms_core_web/forms/snippet_submit.ex#L5)

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.

# `after_save`

```elixir
@spec after_save(
  MishkaGervaz.Form.Web.State.t(),
  struct(),
  Phoenix.LiveView.Socket.t()
) ::
  Phoenix.LiveView.Socket.t()
```

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`

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

# `submit`

```elixir
@spec submit(MishkaGervaz.Form.Web.State.t(), map(), Phoenix.LiveView.Socket.t()) ::
  Phoenix.LiveView.Socket.t()
```

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`

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

Transform params before submission.

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
