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

allSets

Type
craft\elements\GlobalSet[]
Access
Read-only

View source

editableSetIds

Type
array
Access
Read-only

View source

editableSets

Type
craft\elements\GlobalSet[]
Access
Read-only

View source

totalEditableSets

Type
integer
Access
Read-only

View source

totalSets

Type
integer
Access
Read-only

View source

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.
deleteGlobalSetById()Deletes a global set by its ID.
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.
handleChangedGlobalSet()Handle global set change
handleDeletedGlobalSet()Handle global set getting deleted
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.
pruneDeletedField()Prune a deleted field from global set.
saveSet()Saves a global set.
trigger()Triggers an event.

deleteGlobalSetById()

Deletes a global set by its ID.

View source

Arguments

Returns

boolean – Whether the global set was deleted successfully

Throws

getAllSetIds()

Returns all of the global set IDs.

View source

Returns

array

Example

getAllSets()

Returns all global sets.

View source

Returns

craft\elements\GlobalSet[]

Example

getEditableSetIds()

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

View source

Returns

array

Example

getEditableSets()

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

View source

Returns

craft\elements\GlobalSet[]

Example

getSetByHandle()

Returns a global set by its handle.

View source

Arguments

Returns

craft\elements\GlobalSet, null

Example

getSetById()

Returns a global set by its ID.

View source

Arguments

Returns

craft\elements\GlobalSet, null

Example

getTotalEditableSets()

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

View source

Returns

integer

Example

getTotalSets()

Returns the total number of global sets.

View source

Returns

integer

Example

handleChangedGlobalSet()

Handle global set change

View source

Arguments

handleDeletedGlobalSet()

Handle global set getting deleted

View source

Arguments

pruneDeletedField()

Prune a deleted field from global set.

View source

Arguments

saveSet()

Saves a global set.

View source

Arguments

Returns

boolean

Throws

Constants

ConstantDescription
CONFIG_GLOBALSETS_KEY

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.