FieldsService
- Type
- Class
- Namespace
- Craft
- Inherits
- Craft\FieldsService » Craft\BaseApplicationComponent » CApplicationComponent (opens new window) » CComponent (opens new window)
- Implements
IApplicationComponent- Since
- 1.0
Class FieldsService
See also http://craftcms.com
View source (opens new window)
# Public Properties
| Property | Description |
|---|---|
| $behaviors (opens new window) | array (opens new window) – The behaviors that should be attached to this component. |
| $oldFieldColumnPrefix | string (opens new window) |
# $oldFieldColumnPrefix
Signature
public string $oldFieldColumnPrefix = 'field_'
# Public Methods
| Method | Description |
|---|---|
| __call() (opens new window) | Calls the named method which is not a class method. |
| __get() (opens new window) | Returns a property value, an event handler list or a behavior based on its name. |
| __isset() (opens new window) | Checks if a property value is null. |
| __set() (opens new window) | Sets value of a component property. |
| __unset() (opens new window) | Sets a component property to be null. |
| asa() (opens new window) | Returns the named behavior object. |
| assembleLayout() | Assembles a field layout. |
| assembleLayoutFromPost() | Assembles a field layout from post data. |
| attachBehavior() (opens new window) | Attaches a behavior to this component. |
| attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
| attachEventHandler() (opens new window) | Attaches an event handler to an event. |
| canGetProperty() (opens new window) | Determines whether a property can be read. |
| canSetProperty() (opens new window) | 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() (opens new window) | Detaches a behavior from the component. |
| detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
| detachEventHandler() (opens new window) | Detaches an existing event handler. |
| disableBehavior() (opens new window) | Disables an attached behavior. |
| disableBehaviors() (opens new window) | Disables all behaviors attached to this component. |
| doesFieldWithHandleExist() | Returns whether a field exists with a given handle and context. |
| enableBehavior() (opens new window) | Enables an attached behavior. |
| enableBehaviors() (opens new window) | Enables all behaviors attached to this component. |
| evaluateExpression() (opens new window) | 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() (opens new window) | 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() (opens new window) | 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() (opens new window) | Determines whether an event is defined. |
| hasEventHandler() (opens new window) | Checks whether the named event has attached handlers. |
| hasProperty() (opens new window) | Determines whether a property is defined. |
| init() (opens new window) | 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() (opens new window) | 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 (opens new window)
Arguments
$postedFieldLayout(array (opens new window))$requiredFields(array (opens new window))
Returns
Signature
public Craft\FieldLayoutModel assembleLayout ( $postedFieldLayout, $requiredFields = [] )
# assembleLayoutFromPost()
Assembles a field layout from post data.
View source (opens new window)
Arguments
$namespace(string (opens new window), null (opens new window)) – The namespace that the form data was posted in, if any.
Returns
Signature
public Craft\FieldLayoutModel assembleLayoutFromPost ( $namespace = null )
# deleteField()
Signature
public boolean deleteField ( Craft\FieldModel $field )
# deleteFieldById()
Deletes a field by its ID.
View source (opens new window)
Arguments
$fieldId(integer (opens new window))
Returns
Signature
public boolean deleteFieldById ( $fieldId )
# deleteGroupById()
Deletes a field group.
View source (opens new window)
Arguments
$groupId(integer (opens new window))
Returns
Signature
public boolean deleteGroupById ( $groupId )
# deleteLayoutById()
Deletes a field layout(s) by its ID.
View source (opens new window)
Arguments
$layoutId(integer (opens new window), array (opens new window))
Returns
Signature
public boolean deleteLayoutById ( $layoutId )
# deleteLayoutsByType()
Deletes field layouts of a given type.
View source (opens new window)
Arguments
$type(string (opens new window))
Returns
Signature
public boolean deleteLayoutsByType ( $type )
# doesFieldWithHandleExist()
Returns whether a field exists with a given handle and context.
View source (opens new window)
Arguments
$handle(string (opens new window)) – The field handle$context(string (opens new window), null (opens new window)) – The field context (defauts to ContentService::$fieldContext)
Returns
boolean (opens new window) – Whether a field with that handle exists
Signature
public boolean doesFieldWithHandleExist ( $handle, $context = null )
# getAllFieldTypes()
Signature
public array getAllFieldTypes ( )
# getAllFields()
Returns all fields within a field context(s).
View source (opens new window)
Arguments
$indexBy(string (opens new window), null (opens new window)) – The field property to index the resulting fields by$context(string (opens new window), string (opens new window)[], null (opens new window)) – 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 (opens new window)
Arguments
$indexBy(string (opens new window), null (opens new window))
Returns
Signature
public array getAllGroups ( $indexBy = null )
# getFieldByHandle()
Returns a field by its handle.
View source (opens new window)
Arguments
$handle(string (opens new window))
Returns
Signature
public Craft\FieldModel, null getFieldByHandle ( $handle )
# getFieldById()
Returns a field by its ID.
View source (opens new window)
Arguments
$fieldId(integer (opens new window))
Returns
Signature
public Craft\FieldModel, null getFieldById ( $fieldId )
# getFieldType()
Gets a fieldtype.
View source (opens new window)
Arguments
$class(string (opens new window))
Returns
Signature
public Craft\BaseFieldType, null getFieldType ( $class )
# getFieldsByElementType()
Returns all of the fields used by a given element type.
View source (opens new window)
Arguments
$elementTypeClass(string (opens new window))$indexBy(string (opens new window), null (opens new window))
Returns
Signature
public Craft\FieldModel[] getFieldsByElementType ( $elementTypeClass, $indexBy = null )
# getFieldsByGroupId()
Returns all the fields in a given group.
View source (opens new window)
Arguments
$groupId(integer (opens new window))$indexBy(string (opens new window), null (opens new window))
Returns
Signature
public array getFieldsByGroupId ( $groupId, $indexBy = null )
# getFieldsWithContent()
Signature
public array getFieldsWithContent ( )
# getGroupById()
Returns a field group by its ID.
View source (opens new window)
Arguments
$groupId(integer (opens new window))
Returns
Signature
public Craft\FieldGroupModel, null getGroupById ( $groupId )
# getLayoutById()
Returns a field layout by its ID.
View source (opens new window)
Arguments
$layoutId(integer (opens new window))
Returns
Signature
public Craft\FieldLayoutModel, null getLayoutById ( $layoutId )
# getLayoutByType()
Returns a field layout by its type.
View source (opens new window)
Arguments
$type(string (opens new window))
Returns
Signature
public Craft\FieldLayoutModel getLayoutByType ( $type )
# getLayoutFieldsById()
Returns a layout's fields by its ID.
View source (opens new window)
Arguments
$layoutId(integer (opens new window))
Returns
Signature
public array getLayoutFieldsById ( $layoutId )
# getLayoutTabsById()
Returns a layout's tabs by its ID.
View source (opens new window)
Arguments
$layoutId(integer (opens new window))
Returns
Signature
public array getLayoutTabsById ( $layoutId )
# getOrderedLayoutFieldsById()
Returns a layout's fields by its ID, in the layout-defined sort order.
View source (opens new window)
Arguments
$layoutId(integer (opens new window))
Returns
Signature
public array getOrderedLayoutFieldsById ( $layoutId )
# onSaveFieldLayout()
Fires an 'onSaveFieldLayout' event.
View source (opens new window)
Arguments
$event(Craft\Event)
Returns
Signature
public null onSaveFieldLayout ( Craft\Event $event )
# populateFieldType()
Populates a fieldtype by a field model.
View source (opens new window)
Arguments
$field(Craft\FieldModel)$element(Craft\BaseElementModel, null (opens new window))
Returns
Signature
public Craft\BaseFieldType, null populateFieldType ( Craft\FieldModel $field, $element = null )
# saveField()
Saves a field.
View source (opens new window)
Arguments
$field(Craft\FieldModel)$validate(boolean (opens new window))
Returns
Throws
Signature
public boolean saveField ( Craft\FieldModel $field, $validate = true )
# saveGroup()
Saves a field group.
View source (opens new window)
Arguments
$group(Craft\FieldGroupModel)
Returns
Signature
public boolean saveGroup ( Craft\FieldGroupModel $group )
# saveLayout()
Saves a field layout.
View source (opens new window)
Arguments
$layout(Craft\FieldLayoutModel)
Returns
Signature
public boolean saveLayout ( Craft\FieldLayoutModel $layout )
# validateField()
Validates a field's settings.
View source (opens new window)
Arguments
$field(Craft\FieldModel)
Returns
Signature
public boolean validateField ( Craft\FieldModel $field )