Documentation

FlexObjectInterface extends FlexCommonInterface, NestedObjectInterface, ArrayAccess

Defines Flex Objects.

Tags
extends
used-by

\Grav\Framework\Flex\FlexObject

since
1.6

Table of Contents

Methods

__construct()  : mixed
Construct a new Flex Object instance.
create()  : static
Create new object into the storage.
defNestedProperty()  : $this
defProperty()  : $this
delete()  : static
Delete object from the storage.
exists()  : bool
Returns true if the object exists in the storage.
getBlueprint()  : Blueprint
Returns the blueprint of the object.
getCacheChecksum()  : string
Get cache checksum for the object / collection.
getCacheKey()  : string
Get a cache key which is used for caching the object / collection.
getDefaultValue()  : mixed|null
Returns default value suitable to be used in a form for the given property.
getDefaultValues()  : array<string|int, mixed>
Returns default values suitable to be used in a form for the given property.
getFlexDirectory()  : FlexDirectory
Get Flex Directory for the object / collection.
getFlexFeatures()  : array<string|int, mixed>
Get full list of features the object / collection implements.
getFlexKey()  : string
Get a unique key for the object.
getFlexType()  : string
Get Flex Type of the object / collection.
getForm()  : FlexFormInterface
Returns a form instance for the object.
getFormValue()  : mixed
Returns raw value suitable to be used in a form for the given property.
getKey()  : string
getMetaData()  : array<string|int, mixed>
Get index data associated to the object.
getNestedProperty()  : mixed|array<string|int, mixed>
getProperty()  : mixed
getStorageKey()  : string
Get an unique storage key (within the directory) which is used for figuring out the filename or database id.
getTimestamp()  : int
Get last updated timestamp for the object / collection.
getType()  : string
hasFlexFeature()  : bool
Test whether the feature is implemented in the object / collection.
hasKey()  : bool
Returns true if object has a key.
hasNestedProperty()  : bool|array<string|int, bool>
hasProperty()  : bool
prepareStorage()  : array<string|int, mixed>
Prepare object for saving into the storage.
render()  : ContentBlockInterface|HtmlBlock
Renders the object.
save()  : static
Save object into the storage.
search()  : float
Search a string from the object, returns weight between 0 and 1.
setNestedProperty()  : $this
setProperty()  : $this
unsetNestedProperty()  : $this
unsetProperty()  : $this
update()  : static
Updates object in the memory.

Methods

__construct()

Construct a new Flex Object instance.

public __construct(array<string|int, mixed> $elements, string $key, FlexDirectory $directory[, bool $validate = false ]) : mixed
Parameters
$elements : array<string|int, mixed>

Array of object properties.

$key : string

Identifier key for the new object.

$directory : FlexDirectory

Flex Directory the object belongs into.

$validate : bool = false

True if the object should be validated against blueprint.

Tags
used-by

FlexDirectory::createObject() Method to create Flex Object.

throws
InvalidArgumentException

create()

Create new object into the storage.

public create([string|null $key = null ]) : static
APIYes
Parameters
$key : string|null = null

Optional new key. If key isn't given, random key will be associated to the object.

Tags
see
FlexDirectory::createObject()

If you want to create a new object instance.

see
FlexObjectInterface::update()

If you want to update properties of the object.

throws
RuntimeException

if object already exists.

Return values
static

defNestedProperty()

public defNestedProperty(string $property, mixed $default[, string|null $separator = null ]) : $this
Parameters
$property : string

Object property to be defined.

$default : mixed

Default value.

$separator : string|null = null

Separator, defaults to '.'

Tags
throws
RuntimeException
Return values
$this

defProperty()

public defProperty(string $property, mixed $default) : $this
Parameters
$property : string

Object property to be defined.

$default : mixed

Default value.

Return values
$this

delete()

Delete object from the storage.

public delete() : static
APIYes
Return values
static

exists()

Returns true if the object exists in the storage.

public exists() : bool
APIYes
Return values
bool —

Returns true if the object exists, false otherwise.

getBlueprint()

Returns the blueprint of the object.

public getBlueprint([string $name = '' ]) : Blueprint
Parameters
$name : string = ''

Name of the Blueprint form. Used to create customized forms for different use cases.

Tags
see
FlexObjectInterface::getForm()
used-by

FlexForm::getBlueprint()

Return values
Blueprint —

Returns a Blueprint.

getCacheChecksum()

Get cache checksum for the object / collection.

public getCacheChecksum() : string

If checksum changes, cache gets invalided.

Return values
string —

Returns cache checksum.

getCacheKey()

Get a cache key which is used for caching the object / collection.

public getCacheKey() : string
Return values
string —

Returns cache key.

getDefaultValue()

Returns default value suitable to be used in a form for the given property.

public getDefaultValue(string $name[, string|null $separator = null ]) : mixed|null
Parameters
$name : string

Property name.

$separator : string|null = null

Optional nested property separator.

Tags
see
FlexObjectInterface::getForm()
Return values
mixed|null —

Returns default value of the field, null if there is no default value.

getDefaultValues()

Returns default values suitable to be used in a form for the given property.

public getDefaultValues() : array<string|int, mixed>
Tags
see
FlexObjectInterface::getForm()
Return values
array<string|int, mixed> —

Returns default values.

getFlexFeatures()

Get full list of features the object / collection implements.

public getFlexFeatures() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFlexKey()

Get a unique key for the object.

public getFlexKey() : string
APIYes

Flex Keys can be used without knowing the Directory the Object belongs into.

Tags
see
Flex::getObject()

If you want to get Flex Object from any Flex Directory.

see
Flex::getObjects()

If you want to get list of Flex Objects from any Flex Directory.

NOTE: Please do not override the method!

Return values
string —

Returns Flex Key of the object.

getFlexType()

Get Flex Type of the object / collection.

public getFlexType() : string
APIYes
Return values
string —

Returns Flex Type of the collection.

getForm()

Returns a form instance for the object.

public getForm([string $name = '' ][, array<string|int, mixed>|null $options = null ]) : FlexFormInterface
APIYes
Parameters
$name : string = ''

Name of the form. Can be used to create customized forms for different use cases.

$options : array<string|int, mixed>|null = null

Options can be used to further customize the form.

Return values
FlexFormInterface —

Returns a Form.

getFormValue()

Returns raw value suitable to be used in a form for the given property.

public getFormValue(string $name[, mixed $default = null ][, string|null $separator = null ]) : mixed
Parameters
$name : string

Property name.

$default : mixed = null

Default value.

$separator : string|null = null

Optional nested property separator.

Tags
see
FlexObjectInterface::getForm()
Return values
mixed —

Returns value of the field.

getMetaData()

Get index data associated to the object.

public getMetaData() : array<string|int, mixed>
Return values
array<string|int, mixed> —

Returns metadata of the object.

getNestedProperty()

public getNestedProperty(string $property[, mixed|null $default = null ][, string|null $separator = null ]) : mixed|array<string|int, mixed>
Parameters
$property : string

Object property to be fetched.

$default : mixed|null = null

Default value if property has not been set.

$separator : string|null = null

Separator, defaults to '.'

Return values
mixed|array<string|int, mixed> —

Property value.

getProperty()

public getProperty(string $property[, mixed|null $default = null ]) : mixed
Parameters
$property : string

Object property to be fetched.

$default : mixed|null = null

Default value if property has not been set.

Return values
mixed —

Property value.

getStorageKey()

Get an unique storage key (within the directory) which is used for figuring out the filename or database id.

public getStorageKey() : string
APIYes
Tags
see
FlexDirectory::getObject()

If you want to get Flex Object from the Flex Directory.

see
FlexDirectory::getCollection()

If you want to get Flex Collection with selected keys from the Flex Directory.

Return values
string —

Returns storage key of the Object.

getTimestamp()

Get last updated timestamp for the object / collection.

public getTimestamp() : int
APIYes
Return values
int —

Returns Unix timestamp.

hasFlexFeature()

Test whether the feature is implemented in the object / collection.

public hasFlexFeature(string $name) : bool
Parameters
$name : string
Return values
bool

hasKey()

Returns true if object has a key.

public hasKey() : bool
Return values
bool

hasNestedProperty()

public hasNestedProperty(string $property[, string|null $separator = null ]) : bool|array<string|int, bool>
Parameters
$property : string

Object property name.

$separator : string|null = null

Separator, defaults to '.'

Return values
bool|array<string|int, bool> —

True if property has been defined (can be null).

hasProperty()

public hasProperty(string $property) : bool
Parameters
$property : string

Object property name.

Return values
bool —

True if property has been defined (property can be null).

prepareStorage()

Prepare object for saving into the storage.

public prepareStorage() : array<string|int, mixed>
Return values
array<string|int, mixed> —

Returns an array of object properties containing only scalars and arrays.

render()

Renders the object.

public render([string|null $layout = null ][, array<string|int, mixed> $context = [] ]) : ContentBlockInterface|HtmlBlock
APIYes
Parameters
$layout : string|null = null

Layout to be used.

$context : array<string|int, mixed> = []

Extra context given to the renderer.

Tags
example

$block = $object->render('custom', ['variable' => 'value']);

example

{% render object layout 'custom' with { variable: 'value' } %}

Return values
ContentBlockInterface|HtmlBlock —

Returns HtmlBlock containing the rendered output.

Search a string from the object, returns weight between 0 and 1.

public search(string $search[, string|array<string|int, string>|null $properties = null ][, array<string|int, mixed>|null $options = null ]) : float
APIYes

Note: If you override this function, make sure you return value in range 0...1!

Parameters
$search : string

Search string.

$properties : string|array<string|int, string>|null = null

Properties to search for, defaults to configured properties.

$options : array<string|int, mixed>|null = null

Search options, defaults to configured options.

Tags
used-by

FlexCollectionInterface::search() If you want to search a string from a Flex Collection.

Return values
float —

Returns a weight between 0 and 1.

setNestedProperty()

public setNestedProperty(string $property, mixed $value[, string|null $separator = null ]) : $this
Parameters
$property : string

Object property to be updated.

$value : mixed

New value.

$separator : string|null = null

Separator, defaults to '.'

Tags
throws
RuntimeException
Return values
$this

setProperty()

public setProperty(string $property, mixed $value) : $this
Parameters
$property : string

Object property to be updated.

$value : mixed

New value.

Return values
$this

unsetNestedProperty()

public unsetNestedProperty(string $property[, string|null $separator = null ]) : $this
Parameters
$property : string

Object property to be unset.

$separator : string|null = null

Separator, defaults to '.'

Tags
throws
RuntimeException
Return values
$this

unsetProperty()

public unsetProperty(string $property) : $this
Parameters
$property : string

Object property to be unset.

Return values
$this

update()

Updates object in the memory.

public update(array<string|int, mixed> $data[, array<string|int, mixed>|array<string|int, UploadedFileInterface> $files = [] ]) : static
APIYes
Parameters
$data : array<string|int, mixed>

Data containing updated properties with their values. To unset a value, use null.

$files : array<string|int, mixed>|array<string|int, UploadedFileInterface> = []

List of uploaded files to be saved within the object.

Tags
see
FlexObjectInterface::save()

You need to save the object after calling this method.

throws
RuntimeException
Return values
static

        
On this page

Search results