Craft 2 Class Reference

Class FieldsService

Package
craft.app.services
Namespace
Craft
Inheritance
class FieldsService » BaseApplicationComponent » \CApplicationComponent » \CComponent
Implements
\IApplicationComponent
Since
1.0
Source Code
craft/app/services/FieldsService.php

Class FieldsService

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

Property Details

allFieldTypes public property #

Returns all installed fieldtypes.

public array getAllFieldTypes()

allFields public property #

Returns all fields within a field context(s).

public FieldModel[] getAllFields(string|null $indexBy = null, array $context = null)

allGroups public property #

Returns all field groups.

public array getAllGroups(string|null $indexBy = null)

fieldsWithContent public property #

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

public array getFieldsWithContent()

oldFieldColumnPrefix public property #

public string $oldFieldColumnPrefix;

Method Details

assembleLayout() public method #

Assembles a field layout.

public FieldLayoutModel assembleLayout(array $postedFieldLayout, array $requiredFields = array (
))
$postedFieldLayout array
$requiredFields array
Returns FieldLayoutModel

assembleLayoutFromPost() public method #

Assembles a field layout from post data.

public FieldLayoutModel assembleLayoutFromPost(string|null $namespace = null)
$namespace string / null The namespace that the form data was posted in, if any.
Returns FieldLayoutModel

deleteField() public method #

Deletes a field.

public bool deleteField(FieldModel $field)
$field FieldModel
Returns bool

deleteFieldById() public method #

Deletes a field by its ID.

public bool deleteFieldById(int $fieldId)
$fieldId int
Returns bool

deleteGroupById() public method #

Deletes a field group.

public bool deleteGroupById(int $groupId)
$groupId int
Returns bool

deleteLayoutById() public method #

Deletes a field layout(s) by its ID.

public bool deleteLayoutById(int|array $layoutId)
$layoutId int / array
Returns bool

deleteLayoutsByType() public method #

Deletes field layouts of a given type.

public bool deleteLayoutsByType(string $type)
$type string
Returns bool

doesFieldWithHandleExist() public method #

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

public bool doesFieldWithHandleExist(string $handle, string|null $context = null)
$handle string The field handle
$context string / null The field context (defauts to ContentService::$fieldContext)
Returns bool Whether a field with that handle exists

getAllFieldTypes() public method #

Returns all installed fieldtypes.

public array getAllFieldTypes()
Returns array

getAllFields() public method #

Returns all fields within a field context(s).

public FieldModel[] getAllFields(string|null $indexBy = null, array $context = null)
$indexBy string / null The field property to index the resulting fields by
$context array The field context(s) to fetch fields from. Defaults to ContentService::$fieldContext.
Returns FieldModel[] The resulting fields

getAllGroups() public method #

Returns all field groups.

public array getAllGroups(string|null $indexBy = null)
$indexBy string / null
Returns array

getFieldByHandle() public method #

Returns a field by its handle.

public FieldModel|null getFieldByHandle(string $handle)
$handle string
Returns FieldModel / null

getFieldById() public method #

Returns a field by its ID.

public FieldModel|null getFieldById(int $fieldId)
$fieldId int
Returns FieldModel / null

getFieldType() public method #

Gets a fieldtype.

public BaseFieldType|null getFieldType(string $class)
$class string
Returns BaseFieldType / null

getFieldsByElementType() public method #

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

public FieldModel[] getFieldsByElementType(string $elementTypeClass, string|null $indexBy = null)
$elementTypeClass string
$indexBy string / null
Returns FieldModel[]

getFieldsByGroupId() public method #

Returns all the fields in a given group.

public array getFieldsByGroupId(int $groupId, string|null $indexBy = null)
$groupId int
$indexBy string / null
Returns array

getFieldsWithContent() public method #

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

public array getFieldsWithContent()
Returns array

getGroupById() public method #

Returns a field group by its ID.

public FieldGroupModel|null getGroupById(int $groupId)
$groupId int
Returns FieldGroupModel / null

getLayoutById() public method #

Returns a field layout by its ID.

public FieldLayoutModel|null getLayoutById(int $layoutId)
$layoutId int
Returns FieldLayoutModel / null

getLayoutByType() public method #

Returns a field layout by its type.

public FieldLayoutModel getLayoutByType(string $type)
$type string
Returns FieldLayoutModel

getLayoutFieldsById() public method #

Returns a layout's fields by its ID.

public array getLayoutFieldsById(int $layoutId)
$layoutId int
Returns array

getLayoutTabsById() public method #

Returns a layout's tabs by its ID.

public array getLayoutTabsById(int $layoutId)
$layoutId int
Returns array

getOrderedLayoutFieldsById() public method #

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

public array getOrderedLayoutFieldsById(int $layoutId)
$layoutId int
Returns array

onSaveFieldLayout() public method #

Fires an 'onSaveFieldLayout' event.

public null onSaveFieldLayout(Event $event)
$event Event

populateFieldType() public method #

Populates a fieldtype by a field model.

public BaseFieldType|null populateFieldType(FieldModel $field, BaseElementModel|null $element = null)
$field FieldModel
$element BaseElementModel / null
Returns BaseFieldType / null

saveField() public method #

Saves a field.

public bool saveField(FieldModel $field, bool $validate = true)
$field FieldModel
$validate bool
Returns bool

saveGroup() public method #

Saves a field group.

public bool saveGroup(FieldGroupModel $group)
$group FieldGroupModel
Returns bool

saveLayout() public method #

Saves a field layout.

public bool saveLayout(FieldLayoutModel $layout)
$layout FieldLayoutModel
Returns bool

validateField() public method #

Validates a field's settings.

public bool validateField(FieldModel $field)
$field FieldModel
Returns bool