Render Object
render()
render( [layout], [context] ): Block Renders the object.
Parameters:
- layout Layout name (
string) - context Extra variables that can be used inside the Twig template file (
array)
Returns:
- Block (
object) HtmlBlock class containing the output
Note
NOTE: In twig there is a {% render %} tag, which should be used instead of calling the method directly. This will allow JS/CSS assets from the object to work properly.
{% set contact = grav.get('flex').object('gizwsvkyo5xtms2s', 'contacts') %}
{% render contact layout: 'details' with { my_variable: true } %}
use Grav\Common\Grav;
use Grav\Framework\ContentBlock\HtmlBlock;
use Grav\Framework\Flex\Interfaces\FlexObjectInterface;
/** @var FlexObjectInterface|null $collection */
$object = Grav::instance()->get('flex')->getObject('gizwsvkyo5xtms2s', 'contacts');
if ($object) {
/** @var HtmlBlock $block */
$block = $object->render('details', ['my_variable' => true]);
}
Other
getKey()
getKey(): string Get key of the object.
Returns:
stringObject key
hasKey()
hasKey(): bool Returns true if the object key has been set.
Returns:
trueif object has a key,falseotherwise
getFlexType()
getFlexType(): string Get type of the object.
Returns:
stringFlex directory name where the object belongs into
hasProperty()
hasProperty( property ): bool Returns true if the object property has been defined and has a value (not null).
Parameters:
- property Property name (
string)
Returns:
trueif property has a value,falseotherwise.
getProperty()
getProperty( property, default ): mixed Returns the value of the object property.
Parameters:
- property Property name (
string)
Returns:
mixedValue of the propertynullif the property is not defined or has no value
setProperty()
setProperty( property, value ): Object Set new value to the object property.
Parameters:
- property Property name (
string) - value New value (
mixed)
Returns:
- Object (
object) The object for chaining the method calls
Caution
WARNING: This method modifies the object instance shared between all the collections. If that is not intended, please clone the object before using this method.
defProperty()
defProperty( property, default ): Object Define default value to the object property.
Parameters:
- property Property name (
string) - default Default value (
mixed)
Returns:
- Object (
object) The object for chaining the method calls
Caution
WARNING: This method modifies the object instance shared between all the collections. If that is not intended, please clone the object before using this method.
unsetProperty()
unsetProperty( property ): Object Remove value of the object property.
Parameters:
- property Property name (
string)
Returns:
- Object (
object) The object for chaining the method calls
Caution
WARNING: This method modifies the object instance shared between all the collections. If that is not intended, please clone the object before using this method.
isAuthorized()
isAuthorized( action, [scope], [user] ): bool | null Check if user is authorized for the action.
Parameters:
- action (
string)- One of:
create,read,update,delete,list
- One of:
- scope Optional (
string)- Usually either
adminorsite
- Usually either
- user Optional User Object (
object)
Returns:
trueAllow actionfalseDeny actionnullNot set (acts as Deny)
Note
Note: There are two deny values: denied (false), not set (null). This allows chaining multiple rules together when the previous rules were not matched.`
getFlexDirectory()
getFlexDirectory(): Directory
Returns:
- Directory (
object)
getTimestamp()
getTimestamp(): int Get last modified timestamp for the object.
Returns:
intTimestamp.
search()
search(string, [properties], [options] ): float Search a string from the object, returns weight between 0 and 1.
Parameters:
- string Search string (
string) - properties Properties to search, if null (or not provided), use defaults (
arrayornull) - options Extra options used while searching (
array)- starts_with:
bool - ends_with:
bool - contains:
bool - case_sensitive:
bool
- starts_with:
Returns:
floatSearch weight between 0 and 1, used for ordering the results0Object does not match the search
Note
Note: If you override this function, make sure you return value in range 0...1!
getFlexKey()
getFlexKey(): string Get a unique key for the object.
Returns:
stringFlex key of the object
Flex Keys can be used without knowing the Directory the Object belongs into.
getStorageKey()
getStorageKey(): string Get a unique storage key (within the directory) which is used for figuring out the filename or database id.
Returns:
stringStorage key of the object
exists()
exists(): bool Returns true if the object exists in the storage.
Returns:
trueObject exists in the storagefalseObject has not been saved
update()
update( data, files ): Object Updates object in the memory.
Parameters:
- data (
array) Nested arrays of properties with their values - files (
array) Array ofPsr\Http\Message\UploadedFileInterfaceobjects
Returns:
- Object (
object) The object for chaining the method calls
Warning
TIP: You need to save the object after calling this method.
create()
create( [key] ): Object Create new object into the storage.
Parameters:
- key (
string) Optional key
Returns:
- Object (
object) Saved object
createCopy()
createCopy( [key] ): Object Create a new object from the current one and save it into the storage.
Parameters:
- key (
string) Optional key
Returns:
- Object (
object) Saved object
save()
save(): Object Save object into the storage.
Returns:
- Object (
object) Saved object
delete()
delete(): Object Delete object from the storage.
Returns:
- Object (
object) Deleted object
getBlueprint()
getBlueprint( [name] ): Blueprint Returns the blueprint of the object.
Parameters:
- name (
string) Optional name for the blueprint
Returns:
- Blueprint (
object)
getForm()
getForm( [name], [options] ): Form Returns a form instance for the object.
Parameters:
- name (
string) Optional name for the form - options (
array) Optional options to the form
Returns:
- Form (
object)
getDefaultValue()
getDefaultValue( name, [separator] ): mixed Returns default value suitable to be used in a form for the given property.
Parameters:
- name (
string) Name of the property - separator (
string) Optional separator character for nested properties, defaults to.(dot)
Returns:
mixedDefault value of the property
getDefaultValues()
getDefaultValues(): array Returns default values suitable to be used in a form for the given property.
Returns:
arrayAll default values
getFormValue()
getFormValue( name, [default], [separator] ): mixed Returns raw value suitable to be used in a form for the given property.
Parameters:
- name (
string) Name of the property - default (
mixed) Optional default value of the field,nullif not given - separator (
string) Optional separator character for nested properties, defaults to.(dot)
Returns:
mixedValue of the form field
triggerEvent()
triggerEvent( name, [Event] ): Object Trigger an event of your choice.
Parameters:
- name (
string) Name of the event - Event (
object) Optional event class
Returns:
- Object (
object) The object for chaining the method calls