Globals ​
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\Globals » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 3.0.0
Globals service.
An instance of the service is available via Craft::$app->globals
.
Public Properties ​
Property | Description |
---|---|
allSetIds | array |
allSets | craft\elements\GlobalSet[] |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
editableSetIds | array |
editableSets | craft\elements\GlobalSet[] |
totalEditableSets | integer |
totalSets | integer |
allSetIds
​
- Type
- array
- Default value
null
- Access
- Read-only
allSets
​
- Type
- craft\elements\GlobalSet[]
- Default value
null
- Access
- Read-only
editableSetIds
​
- Type
- array
- Default value
null
- Access
- Read-only
editableSets
​
- Type
- craft\elements\GlobalSet[]
- Default value
null
- Access
- Read-only
totalEditableSets
​
- Type
- integer
- Default value
null
- Access
- Read-only
totalSets
​
- Type
- integer
- Default value
null
- Access
- Read-only
Public Methods ​
Method | Description |
---|---|
__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 a component property. |
__isset() | Checks if a property is set, i.e. defined and not null. |
__serialize() | Serializer |
__set() | Sets the value of a component property. |
__unset() | Sets a component property to be 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. |
deleteSet() | 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 for this component. |
init() | Initializes the object. |
off() | Detaches an existing event handler from this component. |
on() | Attaches an event handler to an event. |
pruneDeletedField() | |
reorderSets() | Reorders global sets. |
reset() | Resets the memoized globals. |
saveSet() | Saves a global set. |
trigger() | Triggers an event. |
__serialize()
​
- Since
- 3.5.14
Serializer
deleteGlobalSetById()
​
Deletes a global set by its ID.
Arguments ​
$globalSetId
(integer)
Returns ​
boolean – Whether the global set was deleted successfully
Throws ​
- Throwable
if reasons
deleteSet()
​
- Since
- 3.6.0
Deletes a global set by its ID.
Arguments ​
$globalSet
(craft\elements\GlobalSet)
getAllSetIds()
​
Returns all of the global set IDs.
Returns ​
Example ​
$globalSetIds = Craft::$app->globals->allSetIds;
{% set globalSetIds = craft.app.globals.allSetIds %}
getAllSets()
​
Returns all global sets.
Returns ​
Example ​
$globalSets = Craft::$app->globals->allSets;
{% set globalSets = craft.app.globals.allSets %}
getEditableSetIds()
​
Returns all of the global set IDs that are editable by the current user.
Returns ​
Example ​
$globalSetIds = Craft::$app->globals->editableSetIds;
{% set globalSetIds = craft.app.globals.editableSetIds %}
getEditableSets()
​
Returns all global sets that are editable by the current user.
Returns ​
Example ​
$globalSets = Craft::$app->globals->editableSets;
{% set globalSets = craft.app.globals.editableSets %}
getSetByHandle()
​
Returns a global set by its handle.
Arguments ​
Returns ​
craft\elements\GlobalSet, null
Example ​
$globalSet = Craft::$app->globals->getSetByHandle('footerInfo');
{% set globalSet = craft.app.globals.getSetByHandle('footerInfo') %}
getSetById()
​
Returns a global set by its ID.
Arguments ​
Returns ​
craft\elements\GlobalSet, null
Example ​
$globalSet = Craft::$app->globals->getSetById(1);
{% set globalSet = craft.app.globals.getSetById(1) %}
getTotalEditableSets()
​
Returns the total number of global sets that are editable by the current user.
Returns ​
Example ​
$total = Craft::$app->globals->totalEditableSets;
{% set total = craft.app.globals.totalEditableSets %}
getTotalSets()
​
Returns the total number of global sets.
Returns ​
Example ​
$total = Craft::$app->globals->totalSets;
{% set total = craft.app.globals.totalSets %}
handleChangedGlobalSet()
​
Handle global set change
Arguments ​
$event
(craft\events\ConfigEvent)
handleDeletedGlobalSet()
​
Handle global set getting deleted
Arguments ​
$event
(craft\events\ConfigEvent)
pruneDeletedField()
​
DEPRECATED
Deprecated in 3.7.51. Unused fields will be pruned automatically as field layouts are resaved.
reorderSets()
​
- Since
- 3.7.0
Reorders global sets.
Arguments ​
$setIds
(array)
Returns ​
Throws ​
reset()
​
- Since
- 3.6.0
Resets the memoized globals.
saveSet()
​
Saves a global set.
Arguments ​
$globalSet
(craft\elements\GlobalSet) – The global set to be saved$runValidation
(boolean) – Whether the global set should be validated
Returns ​
Throws ​
- craft\errors\GlobalSetNotFoundException
if $globalSet->id is invalid - Throwable
if reasons
Constants ​
Constant | Description |
---|---|
CONFIG_GLOBALSETS_KEY |
Events ​
EVENT_AFTER_SAVE_GLOBAL_SET ​
The event that is triggered after a global set is saved.
EVENT_BEFORE_SAVE_GLOBAL_SET ​
The event that is triggered before a global set is saved.