Group management functions for the Publishing module.
Handles creating, listing, updating, and removing publishing groups, as well as slug generation, type/mode normalization, and item naming.
Summary
Functions
Adds a new publishing group.
Gets a publishing group by slug.
Returns the configured post mode for a publishing group slug.
Looks up a publishing group name from its slug.
Returns all publishing groups from the database.
Lists groups filtered by status (e.g. 'active', 'trashed').
Lists trashed publishing groups.
Returns the preset content types with their default item names.
Removes a publishing group by slug.
Removes a publishing group by slug.
Restores a trashed publishing group.
Moves a publishing group to trash (soft-delete).
Updates a publishing group's display name and slug.
Returns the list of valid group type values.
Types
@type group() :: map()
Functions
Adds a new publishing group.
Parameters
name- Display name for the groupopts- Keyword list or map with options::mode- Post mode: "timestamp" or "slug" (default: "timestamp"):slug- Optional custom slug, auto-generated from name if nil:type- Content type: "blog", "faq", "legal", or custom (default: "blog"):item_singular- Singular name for items (default: based on type, e.g., "post"):item_plural- Plural name for items (default: based on type, e.g., "posts")
Examples
iex> Groups.add_group("News")
{:ok, %{"name" => "News", "slug" => "news", "mode" => "timestamp", "type" => "blog", ...}}
iex> Groups.add_group("FAQ", type: "faq", mode: "slug")
{:ok, %{"name" => "FAQ", "slug" => "faq", "mode" => "slug", "type" => "faq", "item_singular" => "question", ...}}
iex> Groups.add_group("Recipes", type: "custom", item_singular: "recipe", item_plural: "recipes")
{:ok, %{"name" => "Recipes", ..., "item_singular" => "recipe", "item_plural" => "recipes"}}
Gets a publishing group by slug.
Examples
iex> Groups.get_group("news")
{:ok, %{"name" => "News", "slug" => "news", ...}}
iex> Groups.get_group("nonexistent")
{:error, :not_found}
Returns the configured post mode for a publishing group slug.
Looks up a publishing group name from its slug.
@spec list_groups() :: [group()]
Returns all publishing groups from the database.
Lists groups filtered by status (e.g. 'active', 'trashed').
@spec list_trashed_groups() :: [map()]
Lists trashed publishing groups.
@spec preset_types() :: [map()]
Returns the preset content types with their default item names.
Removes a publishing group by slug.
Removes a publishing group by slug.
By default, refuses to delete groups that contain posts.
Pass force: true to cascade-delete the group and all its posts.
Restores a trashed publishing group.
Moves a publishing group to trash (soft-delete).
Sets the group status to "trashed". The group and its posts remain in the database and can be restored. Trashed groups are hidden from list_groups/0.
@spec update_group(String.t(), map() | keyword(), keyword() | map()) :: {:ok, group()} | {:error, atom()}
Updates a publishing group's display name and slug.
@spec valid_types() :: [String.t()]
Returns the list of valid group type values.