Globals

Type
Class
Namespace
craft\services
Inherits
craft\services\Globals » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0

Globals service.

An instance of the Globals service is globally accessible in Craft via Craft::$app->globals.

View source

Public Properties

$allSetIds

Type
array
Access
Read-only

View source

Signature

public array getAllSetIds ( )

$allSets

Signature

public craft\elements\GlobalSet[] getAllSets ( )

$editableSetIds

Type
array
Access
Read-only

View source

Signature

public array getEditableSetIds ( )

$editableSets

Signature

public craft\elements\GlobalSet[] getEditableSets ( )

$totalEditableSets

Type
integer
Access
Read-only

View source

Signature

public integer getTotalEditableSets ( )

$totalSets

Type
integer
Access
Read-only

View source

Signature

public integer getTotalSets ( )

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
behaviors()Returns a list of behaviors that this component should behave as.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
getAllSetIds()Returns all of the global set IDs.
getAllSets()Returns all global sets.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getEditableSetIds()Returns all of the global set IDs that are editable by the current user.
getEditableSets()Returns all global sets that are editable by the current user.
getSetByHandle()Returns a global set by its handle.
getSetById()Returns a global set by its ID.
getTotalEditableSets()Returns the total number of global sets that are editable by the current user.
getTotalSets()Returns the total number of global sets.
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
saveSet()Saves a global set.
trigger()Triggers an event.

getAllSetIds()

Returns all of the global set IDs.

View source

Returns

array

Signature

public array getAllSetIds ( )

Example

getAllSets()

Returns all global sets.

View source

Returns

craft\elements\GlobalSet[]

Signature

public craft\elements\GlobalSet[] getAllSets ( )

Example

getEditableSetIds()

Returns all of the global set IDs that are editable by the current user.

View source

Returns

array

Signature

public array getEditableSetIds ( )

Example

getEditableSets()

Returns all global sets that are editable by the current user.

View source

Returns

craft\elements\GlobalSet[]

Signature

public craft\elements\GlobalSet[] getEditableSets ( )

Example

getSetByHandle()

Returns a global set by its handle.

View source

Arguments

Returns

craft\elements\GlobalSet, null

Signature

public craft\elements\GlobalSet, null getSetByHandle ( \craft\services\string $globalSetHandle, \craft\services\int $siteId = null )

Example

getSetById()

Returns a global set by its ID.

View source

Arguments

Returns

craft\elements\GlobalSet, null

Signature

public craft\elements\GlobalSet, null getSetById ( \craft\services\int $globalSetId, \craft\services\int $siteId = null )

Example

getTotalEditableSets()

Returns the total number of global sets that are editable by the current user.

View source

Returns

integer

Signature

public integer getTotalEditableSets ( )

Example

getTotalSets()

Returns the total number of global sets.

View source

Returns

integer

Signature

public integer getTotalSets ( )

Example

saveSet()

Saves a global set.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean saveSet ( craft\elements\GlobalSet $globalSet, \craft\services\bool $runValidation = true )

Events

EVENT_AFTER_SAVE_GLOBAL_SET

Type
craft\events\GlobalSetEvent

The event that is triggered after a global set is saved.

EVENT_BEFORE_SAVE_GLOBAL_SET

Type
craft\events\GlobalSetEvent

The event that is triggered before a global set is saved.