Fields

Type
Class
Namespace
craft\web\twig\variables
Inherits
craft\web\twig\variables\Fields
Since
3.0
Deprecated in
in 3.0

Fields provides an API for accessing information about fields. It is accessible from templates via craft.fields.

View source

Public Methods

MethodDescription
getAllFieldTypes()Returns all available field type classes.
getAllFields()Returns all fields.
getAllGroups()Returns all field groups.
getFieldByHandle()Returns a field by its handle.
getFieldById()Returns a field by its ID.
getFieldsByGroupId()Returns all the fields in a given group.
getGroupById()Returns a field group by its ID.
getLayoutById()Returns a field layout by its ID.
getLayoutByType()Returns a field layout by its associated element type.

getAllFieldTypes()

Returns all available field type classes.

View source

Returns

string[] – The available field type classes

getAllFields()

Returns all fields.

View source

Arguments

  • $indexBy (string, null) – The attribute to index the fields by

Returns

craft\base\FieldInterface[] – The fields

getAllGroups()

Returns all field groups.

View source

Arguments

  • $indexBy (string, null) – The attribute to index the field groups by

Returns

craft\models\FieldGroup[] – The field groups

getFieldByHandle()

Returns a field by its handle.

View source

Arguments

  • $handle (string) – The field’s handle

Returns

craft\base\FieldInterface, null – The field, or null if it doesn’t exist

getFieldById()

Returns a field by its ID.

View source

Arguments

  • $fieldId (integer) – The field’s ID

Returns

craft\base\FieldInterface, null – The field, or null if it doesn’t exist

getFieldsByGroupId()

Returns all the fields in a given group.

View source

Arguments

  • $groupId (integer) – The field group’s ID
  • $indexBy (string, null) – The attribute to index the fields by

Returns

craft\base\FieldInterface[] – The fields

getGroupById()

Returns a field group by its ID.

View source

Arguments

  • $groupId (integer) – The field group’s ID

Returns

craft\models\FieldGroup, null – The field group, or null if it doesn’t exist

getLayoutById()

Returns a field layout by its ID.

View source

Arguments

  • $layoutId (integer) – The field layout’s ID

Returns

craft\models\FieldLayout, null – The field layout, or null if it doesn’t exist

getLayoutByType()

Returns a field layout by its associated element type.

View source

Arguments

  • $type (string) – The associated element type

Returns

craft\models\FieldLayout – The field layout