Tags

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

Tags service.

An instance of the Tags service is globally accessible in Craft 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
Access
Read-only

View source

Signature

public array getAllTagGroupIds ( )

$allTagGroups

Signature

public craft\models\TagGroup[] getAllTagGroups ( )

$totalTagGroups

Type
integer
Access
Read-only

View source

Signature

public integer getTotalTagGroups ( )

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.
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.
getTotalTagGroups()Gets the total number of tag groups.
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.
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

Signature

public boolean deleteTagGroup ( craft\models\TagGroup $group )

deleteTagGroupById()

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

Signature

public boolean deleteTagGroupById ( \craft\services\int $groupId )

getAllTagGroupIds()

Returns all of the group IDs.

View source

Returns

array

Signature

public array getAllTagGroupIds ( )

getAllTagGroups()

Returns all tag groups.

View source

Returns

craft\models\TagGroup[]

Signature

public craft\models\TagGroup[] getAllTagGroups ( )

getTagById()

Returns a tag by its ID.

View source

Arguments

Returns

craft\elements\Tag, null

Signature

public craft\elements\Tag, null getTagById ( \craft\services\int $tagId, \craft\services\int $siteId = null )

getTagGroupByHandle()

Gets a group by its handle.

View source

Arguments

Returns

craft\models\TagGroup, null

Signature

public craft\models\TagGroup, null getTagGroupByHandle ( \craft\services\string $groupHandle )

getTagGroupById()

Returns a group by its ID.

View source

Arguments

Returns

craft\models\TagGroup, null

Signature

public craft\models\TagGroup, null getTagGroupById ( \craft\services\int $groupId )

getTotalTagGroups()

Gets the total number of tag groups.

View source

Returns

integer

Signature

public integer getTotalTagGroups ( )

saveTagGroup()

Saves a tag group.

View source

Arguments

Returns

boolean – Whether the tag group was saved successfully

Throws

Signature

public boolean saveTagGroup ( craft\models\TagGroup $tagGroup, \craft\services\bool $runValidation = true )

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_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.