Skip to content

Tags ​

Type
Class
Namespace
craft\services
Inherits
craft\services\Tags » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0.0

Tags service.

An instance of the service is available via Craft::$app->tags.

View source

Public Properties ​

PropertyDescription
allTagGroupIdsarray
allTagGroupscraft\models\TagGroup[]
behaviorsyii\base\Behavior – List of behaviors attached to this component.
totalTagGroupsinteger

allTagGroupIds ​

Type
array
Default value
null
Access
Read-only

View source

allTagGroups ​

Type
craft\models\TagGroup[]
Default value
null
Access
Read-only

View source

totalTagGroups ​

Type
integer
Default value
null
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 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.
deleteTagGroup()Deletes a tag group.
deleteTagGroupById()Deletes a tag group 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.
getAllTagGroupIds()Returns all of the group IDs.
getAllTagGroups()Returns all tag groups.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getTagById()Returns a tag by its ID.
getTagGroupByHandle()Gets a group by its handle.
getTagGroupById()Returns a group by its ID.
getTagGroupByUid()Returns a group by its UID.
getTotalTagGroups()Gets the total number of tag groups.
handleChangedTagGroup()Handle tag group change
handleDeletedTagGroup()Handle Tag group 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()
saveTagGroup()Saves a tag group.
trigger()Triggers an event.

__serialize() ​

Since
3.5.14

Serializer

View source

deleteTagGroup() ​

Deletes a tag group.

View source

Arguments ​

Returns ​

boolean – Whether the tag group was deleted successfully

Throws ​

deleteTagGroupById() ​

Since
3.0.12

Deletes a tag group by its ID.

View source

Arguments ​

  • $groupId (integer) – The tag group's ID

Returns ​

boolean – Whether the tag group was deleted successfully

Throws ​

getAllTagGroupIds() ​

Returns all of the group IDs.

View source

Returns ​

array

getAllTagGroups() ​

Returns all tag groups.

View source

Returns ​

craft\models\TagGroup[]

getTagById() ​

Returns a tag by its ID.

View source

Arguments ​

Returns ​

craft\elements\Tag, null

getTagGroupByHandle() ​

Gets a group by its handle.

View source

Arguments ​

Returns ​

craft\models\TagGroup, null

getTagGroupById() ​

Returns a group by its ID.

View source

Arguments ​

Returns ​

craft\models\TagGroup, null

getTagGroupByUid() ​

Returns a group by its UID.

View source

Arguments ​

Returns ​

craft\models\TagGroup, null

getTotalTagGroups() ​

Gets the total number of tag groups.

View source

Returns ​

integer

handleChangedTagGroup() ​

Handle tag group change

View source

Arguments ​

handleDeletedTagGroup() ​

Handle Tag group getting deleted

View source

Arguments ​

pruneDeletedField() ​

DEPRECATED

Deprecated in 3.7.51. Unused fields will be pruned automatically as field layouts are resaved.

View source

saveTagGroup() ​

Saves a tag group.

View source

Arguments ​

  • $tagGroup (craft\models\TagGroup) – The tag group to be saved
  • $runValidation (boolean) – Whether the tag group should be validated

Returns ​

boolean – Whether the tag group was saved successfully

Throws ​

Constants ​

ConstantDescription
CONFIG_TAGGROUP_KEY

Events ​

EVENT_AFTER_DELETE_GROUP ​

Type
craft\events\TagGroupEvent

The event that is triggered after a tag group is deleted.


EVENT_AFTER_SAVE_GROUP ​

Type
craft\events\TagGroupEvent

The event that is triggered after a tag group is saved.


EVENT_BEFORE_APPLY_GROUP_DELETE ​

Type
craft\events\TagGroupEvent
Since
3.1.0

The event that is triggered before a tag group delete is applied to the database.


EVENT_BEFORE_DELETE_GROUP ​

Type
craft\events\TagGroupEvent

The event that is triggered before a tag group is deleted.


EVENT_BEFORE_SAVE_GROUP ​

Type
craft\events\TagGroupEvent

The event that is triggered before a tag group is saved.