ElementorexCms.Source.Field (ElementorexCms v0.2.0)

Copy Markdown View Source

A field of a source (ElementorexCms.Source): what the editor offers when a prop of a block is bound to the data of an item.

  • key - the path of the value in a record ("name", "category.name")
  • label - shown in the editor (translated with ElementorexCms.I18n)
  • type - what the value is, so the editor can suggest it for the right props: :string, :text (several lines), :html (rich text), :integer, :number, :boolean, :date, :datetime, :image (an image URL), :url, :color, :icon or :list
  • sortable / filterable - whether loops can order and filter by it
  • searchable - whether the text search of the visitors' filters looks in it (default: text fields, :string, :text and :html)
  • custom - a filter of the source with logic of its own (in_stock) rather than a value of the records: it can filter but not be shown
  • role - what the field means for templates generated from the source: :title, :image, :description, :price (or nil)
  • defaults - settings of new bindings to the field ("before", "after", "format", "decimals", "length", "fallback"), e.g. a price that starts with "$". See ElementorexCms.Dynamic

Summary

Functions

A field name in words: "image_url" → "Image URL", "category.name" → "Category · Name".

Builds a field. key is a string or an atom; options are the keys of the struct (:label, :type, :sortable, :filterable, :searchable, :custom, :role, :defaults). The label defaults to the key in words (image_url → "Image URL").

Roles a field can have (see the module docs).

The type of a text field guessed from its name: image, photo, *_image_url… are :image; url, link, website, *_url are :url; description, body, summary… are :text; *_html is :html; color is :color; anything else :string.

Types a field can have.

Types

t()

@type t() :: %ElementorexCms.Source.Field{
  custom: boolean(),
  defaults: map(),
  filterable: boolean(),
  key: String.t(),
  label: String.t(),
  role: atom() | nil,
  searchable: boolean(),
  sortable: boolean(),
  type: atom()
}

Functions

humanize(key)

@spec humanize(String.t() | atom()) :: String.t()

A field name in words: "image_url" → "Image URL", "category.name" → "Category · Name".

new(key, opts \\ [])

@spec new(atom() | String.t(), keyword()) :: t()

Builds a field. key is a string or an atom; options are the keys of the struct (:label, :type, :sortable, :filterable, :searchable, :custom, :role, :defaults). The label defaults to the key in words (image_url → "Image URL").

Field.new(:price, type: :number, sortable: true, defaults: %{"before" => "$"})

roles()

@spec roles() :: [atom()]

Roles a field can have (see the module docs).

string_type(key)

@spec string_type(String.t()) :: atom()

The type of a text field guessed from its name: image, photo, *_image_url… are :image; url, link, website, *_url are :url; description, body, summary… are :text; *_html is :html; color is :color; anything else :string.

iex> ElementorexCms.Source.Field.string_type("cover_image_url")
:image
iex> ElementorexCms.Source.Field.string_type("short_description")
:text

types()

@spec types() :: [atom()]

Types a field can have.