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 Tags service is globally accessible in Craft via Craft::$app->tags.

View source

# Public Properties

Property Description
allTagGroupIds array
allTagGroups craft\models\TagGroup[]
behaviors yii\base\Behavior – List of behaviors attached to this component
totalTagGroups integer

# allTagGroupIds

Type
array
Access
Read-only

View source

# allTagGroups

Type
craft\models\TagGroup[]
Access
Read-only

View source

# totalTagGroups

Type
integer
Access
Read-only

View source

# 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 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.
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.
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 tag group layouts.
saveTagGroup() Saves a tag group.
trigger() Triggers an event.

# 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()

Prune a deleted field from tag group layouts.

View source

Arguments

# saveTagGroup()

Saves a tag group.

View source

Arguments

Returns

boolean – Whether the tag group was saved successfully

Throws

# Constants

Constant Description
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.