FieldsService

Type
Class
Namespace
Craft
Inherits
Craft\FieldsService » Craft\BaseApplicationComponent » CApplicationComponent » CComponent
Implements
IApplicationComponent
Since
1.0

Class FieldsService

See also http://craftcms.com

View source

Public Properties

PropertyDescription
$behaviorsarray – The behaviors that should be attached to this component.
$oldFieldColumnPrefixstring

$oldFieldColumnPrefix

Signature

public string $oldFieldColumnPrefix = 'field_'

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__get()Returns a property value, an event handler list or a behavior based on its name.
__isset()Checks if a property value is null.
__set()Sets value of a component property.
__unset()Sets a component property to be null.
asa()Returns the named behavior object.
assembleLayout()Assembles a field layout.
assembleLayoutFromPost()Assembles a field layout from post data.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attachEventHandler()Attaches an event handler to an event.
canGetProperty()Determines whether a property can be read.
canSetProperty()Determines whether a property can be set.
deleteField()Deletes a field.
deleteFieldById()Deletes a field by its ID.
deleteGroupById()Deletes a field group.
deleteLayoutById()Deletes a field layout(s) by its ID.
deleteLayoutsByType()Deletes field layouts of a given type.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
detachEventHandler()Detaches an existing event handler.
disableBehavior()Disables an attached behavior.
disableBehaviors()Disables all behaviors attached to this component.
doesFieldWithHandleExist()Returns whether a field exists with a given handle and context.
enableBehavior()Enables an attached behavior.
enableBehaviors()Enables all behaviors attached to this component.
evaluateExpression()Evaluates a PHP expression or callback under the context of this component.
getAllFieldTypes()Returns all installed fieldtypes.
getAllFields()Returns all fields within a field context(s).
getAllGroups()Returns all field groups.
getEventHandlers()Returns the list of attached event handlers for an event.
getFieldByHandle()Returns a field by its handle.
getFieldById()Returns a field by its ID.
getFieldType()Gets a fieldtype.
getFieldsByElementType()Returns all of the fields used by a given element type.
getFieldsByGroupId()Returns all the fields in a given group.
getFieldsWithContent()Returns all fields that have a column in the content table.
getGroupById()Returns a field group by its ID.
getIsInitialized()Checks if this application component has been initialized.
getLayoutById()Returns a field layout by its ID.
getLayoutByType()Returns a field layout by its type.
getLayoutFieldsById()Returns a layout's fields by its ID.
getLayoutTabsById()Returns a layout's tabs by its ID.
getOrderedLayoutFieldsById()Returns a layout's fields by its ID, in the layout-defined sort order.
hasEvent()Determines whether an event is defined.
hasEventHandler()Checks whether the named event has attached handlers.
hasProperty()Determines whether a property is defined.
init()Initializes the application component.
isInitialized()Checks if this application component has been initialized yet, or not.
onSaveFieldLayout()Fires an 'onSaveFieldLayout' event.
populateFieldType()Populates a fieldtype by a field model.
raiseEvent()Raises an event.
saveField()Saves a field.
saveGroup()Saves a field group.
saveLayout()Saves a field layout.
validateField()Validates a field's settings.

assembleLayout()

Assembles a field layout.

View source

Arguments

Returns

Craft\FieldLayoutModel

Signature

public Craft\FieldLayoutModel assembleLayout ( $postedFieldLayout, $requiredFields = [] )

assembleLayoutFromPost()

Assembles a field layout from post data.

View source

Arguments

  • $namespace (string, null) – The namespace that the form data was posted in, if any.

Returns

Craft\FieldLayoutModel

Signature

public Craft\FieldLayoutModel assembleLayoutFromPost ( $namespace = null )

deleteField()

Deletes a field.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean deleteField ( Craft\FieldModel $field )

deleteFieldById()

Deletes a field by its ID.

View source

Arguments

Returns

boolean

Signature

public boolean deleteFieldById ( $fieldId )

deleteGroupById()

Deletes a field group.

View source

Arguments

Returns

boolean

Signature

public boolean deleteGroupById ( $groupId )

deleteLayoutById()

Deletes a field layout(s) by its ID.

View source

Arguments

Returns

boolean

Signature

public boolean deleteLayoutById ( $layoutId )

deleteLayoutsByType()

Deletes field layouts of a given type.

View source

Arguments

Returns

boolean

Signature

public boolean deleteLayoutsByType ( $type )

doesFieldWithHandleExist()

Returns whether a field exists with a given handle and context.

View source

Arguments

  • $handle (string) – The field handle
  • $context (string, null) – The field context (defauts to ContentService::$fieldContext)

Returns

boolean – Whether a field with that handle exists

Signature

public boolean doesFieldWithHandleExist ( $handle, $context = null )

getAllFieldTypes()

Returns all installed fieldtypes.

View source

Returns

array

Signature

public array getAllFieldTypes ( )

getAllFields()

Returns all fields within a field context(s).

View source

Arguments

  • $indexBy (string, null) – The field property to index the resulting fields by
  • $context (string, string[], null) – The field context(s) to fetch fields from. Defaults to {@link ContentService::$fieldContext}.

Returns

Craft\FieldModel[] – The resulting fields

Signature

public Craft\FieldModel[] getAllFields ( $indexBy = null, $context = null )

getAllGroups()

Returns all field groups.

View source

Arguments

Returns

array

Signature

public array getAllGroups ( $indexBy = null )

getFieldByHandle()

Returns a field by its handle.

View source

Arguments

Returns

Craft\FieldModel, null

Signature

public Craft\FieldModel, null getFieldByHandle ( $handle )

getFieldById()

Returns a field by its ID.

View source

Arguments

Returns

Craft\FieldModel, null

Signature

public Craft\FieldModel, null getFieldById ( $fieldId )

getFieldType()

Gets a fieldtype.

View source

Arguments

Returns

Craft\BaseFieldType, null

Signature

public Craft\BaseFieldType, null getFieldType ( $class )

getFieldsByElementType()

Returns all of the fields used by a given element type.

View source

Arguments

Returns

Craft\FieldModel[]

Signature

public Craft\FieldModel[] getFieldsByElementType ( $elementTypeClass, $indexBy = null )

getFieldsByGroupId()

Returns all the fields in a given group.

View source

Arguments

Returns

array

Signature

public array getFieldsByGroupId ( $groupId, $indexBy = null )

getFieldsWithContent()

Returns all fields that have a column in the content table.

View source

Returns

array

Signature

public array getFieldsWithContent ( )

getGroupById()

Returns a field group by its ID.

View source

Arguments

Returns

Craft\FieldGroupModel, null

Signature

public Craft\FieldGroupModel, null getGroupById ( $groupId )

getLayoutById()

Returns a field layout by its ID.

View source

Arguments

Returns

Craft\FieldLayoutModel, null

Signature

public Craft\FieldLayoutModel, null getLayoutById ( $layoutId )

getLayoutByType()

Returns a field layout by its type.

View source

Arguments

Returns

Craft\FieldLayoutModel

Signature

public Craft\FieldLayoutModel getLayoutByType ( $type )

getLayoutFieldsById()

Returns a layout's fields by its ID.

View source

Arguments

Returns

array

Signature

public array getLayoutFieldsById ( $layoutId )

getLayoutTabsById()

Returns a layout's tabs by its ID.

View source

Arguments

Returns

array

Signature

public array getLayoutTabsById ( $layoutId )

getOrderedLayoutFieldsById()

Returns a layout's fields by its ID, in the layout-defined sort order.

View source

Arguments

Returns

array

Signature

public array getOrderedLayoutFieldsById ( $layoutId )

onSaveFieldLayout()

Fires an 'onSaveFieldLayout' event.

View source

Arguments

Returns

null

Signature

public null onSaveFieldLayout ( Craft\Event $event )

populateFieldType()

Populates a fieldtype by a field model.

View source

Arguments

Returns

Craft\BaseFieldType, null

Signature

public Craft\BaseFieldType, null populateFieldType ( Craft\FieldModel $field, $element = null )

saveField()

Saves a field.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean saveField ( Craft\FieldModel $field, $validate = true )

saveGroup()

Saves a field group.

View source

Arguments

Returns

boolean

Signature

public boolean saveGroup ( Craft\FieldGroupModel $group )

saveLayout()

Saves a field layout.

View source

Arguments

Returns

boolean

Signature

public boolean saveLayout ( Craft\FieldLayoutModel $layout )

validateField()

Validates a field's settings.

View source

Arguments

Returns

boolean

Signature

public boolean validateField ( Craft\FieldModel $field )