\Field\CollectionFieldCollection

Field Collection.

Used for manage fields attached to table entities using Fieldable behavior.

Allows to handle fields as an array list, it also adds a few useful functionalities such as sortAs() method, or accessing a fields by its numeric index or its machine-name (associative array), see offsetGet().

Summary

Methods
Properties
Constants
__construct()
offsetGet()
machineNames()
sortByViewMode()
__debugInfo()
No public properties found
No constants found
No protected methods found
$_keysMap
N/A
No private methods found
No private properties found
N/A

Properties

$_keysMap

$_keysMap : array

Holds a map of machine-names to index keys.

Example:

[
    'user-name' => 0,
    'user-phone' => 1,
    'user-age' => 3,
     // ...
]

Type

array

Methods

__construct()

__construct(array $fields)

Class constructor.

Parameters

array $fields

List of fields

offsetGet()

offsetGet(integer|string $index) : mixed

Allows access fields by numeric index or by machine-name.

Example:

$fields => [
    [0] => [
        [name] => user-age,
        [label] => User Age,
        [value] => 22,
        [extra] => null,
        [metadata] => [ ... ]
    ],
    [1] => [
        [name] => user-phone,
        [label] => User Phone,
        [value] => null,
        [extra] => null,
        [metadata] => [ ... ]
    ]
];

$collection = new FieldCollection($fields);
if ($collection[1] === $collection['user-phone']) {
   echo "SUCCESS";
}

// outputs: SUCCESS

Parameters

integer|string $index

Numeric index or machine-name

Returns

mixed —

\Field\Model\Entity\Field on success or NULL on failure

machineNames()

machineNames() : array

Gets a list of all machine names.

Returns

array —

List of machine names

sortByViewMode()

sortByViewMode(string $viewMode, integer $dir) : \Field\Collection\FieldCollection

Sorts the list of fields by view mode ordering.

Fields might have different orderings for each view mode.

Parameters

string $viewMode

View mode slug to use for sorting

integer $dir

either SORT_DESC or SORT_ASC

Returns

\Field\Collection\FieldCollection

__debugInfo()

__debugInfo() : array

Returns an array that can be used to describe the internal state of this object.

Returns

array