Categories
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\Categories » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window)
- Since
- 3.0.0
Categories service.
An instance of the service is available via Craft::$app->categories
.
View source (opens new window)
# Public Properties
Property | Description |
---|---|
allGroupIds | integer (opens new window)[] |
allGroups | craft\models\CategoryGroup[] |
behaviors (opens new window) | yii\base\Behavior (opens new window) – List of behaviors attached to this component. |
editableGroupIds | integer (opens new window)[] |
editableGroups | craft\models\CategoryGroup[] |
totalGroups | integer (opens new window) |
# allGroupIds
- Type
- integer (opens new window)[]
- Default value
null
- Access
- Read-only
View source (opens new window)
# allGroups
- Type
- craft\models\CategoryGroup[]
- Default value
null
- Access
- Read-only
View source (opens new window)
# editableGroupIds
- Type
- integer (opens new window)[]
- Default value
null
- Access
- Read-only
View source (opens new window)
# editableGroups
- Type
- craft\models\CategoryGroup[]
- Default value
null
- Access
- Read-only
View source (opens new window)
# totalGroups
- Type
- integer (opens new window)
- Default value
null
- Access
- Read-only
View source (opens new window)
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__clone() (opens new window) | This method is called after the object is created by cloning an existing one. |
__construct() (opens new window) | Constructor. |
__get() (opens new window) | Returns the value of a component property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__serialize() | Serializer |
__set() (opens new window) | Sets the value of a component property. |
__unset() (opens new window) | Sets a component property to be null. |
applyBranchLimitToCategories() | Filters an array of categories down to only <= X branches. |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
behaviors() (opens new window) | Returns a list of behaviors that this component should behave as. |
canGetProperty() (opens new window) | Returns a value indicating whether a property can be read. |
canSetProperty() (opens new window) | Returns a value indicating whether a property can be set. |
className() (opens new window) | Returns the fully qualified name of this class. |
deleteGroup() | Deletes a category group. |
deleteGroupById() | Deletes a category group by its ID. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
ensureBehaviors() (opens new window) | Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component. |
fillGapsInCategories() | Patches an array of categories, filling in any gaps in the tree. |
getAllGroupIds() | Returns all of the group IDs. |
getAllGroups() | Returns all category groups. |
getBehavior() (opens new window) | Returns the named behavior object. |
getBehaviors() (opens new window) | Returns all behaviors attached to this component. |
getCategoryById() | Returns a category by its ID. |
getEditableGroupIds() | Returns all of the category group IDs that are editable by the current user. |
getEditableGroups() | Returns all editable groups. |
getGroupByHandle() | Returns a group by its handle. |
getGroupById() | Returns a group by its ID. |
getGroupByUid() | Returns a group by its UID. |
getGroupSiteSettings() | Returns a group's site settings. |
getTotalGroups() | Gets the total number of category groups. |
handleChangedCategoryGroup() | Handle category group change |
handleDeletedCategoryGroup() | Handle Category group getting deleted |
hasEventHandlers() (opens new window) | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() (opens new window) | Returns a value indicating whether a method is defined. |
hasProperty() (opens new window) | Returns a value indicating whether a property is defined for this component. |
init() (opens new window) | Initializes the object. |
isGroupTemplateValid() | Returns whether a group’s categories have URLs for the given site ID, and if the group’s template path is valid. |
off() (opens new window) | Detaches an existing event handler from this component. |
on() (opens new window) | Attaches an event handler to an event. |
pruneDeletedField() | |
pruneDeletedSite() | Prune a deleted site from category group site settings. |
saveGroup() | Saves a category group. |
trigger() (opens new window) | Triggers an event. |
# __serialize()
Serializer
View source (opens new window)
# applyBranchLimitToCategories()
DEPRECATED
Deprecated in 3.6.0. Use craft\services\Structures::applyBranchLimitToElements() instead.
Filters an array of categories down to only <= X branches.
View source (opens new window)
Arguments
$categories
(craft\elements\Category[])$branchLimit
(integer (opens new window))
# deleteGroup()
Deletes a category group.
View source (opens new window)
Arguments
$group
(craft\models\CategoryGroup) – The category group
Returns
boolean (opens new window) – Whether the category group was deleted successfully
# deleteGroupById()
- Since
- 3.0.12
Deletes a category group by its ID.
View source (opens new window)
Arguments
$groupId
(integer (opens new window)) – The category group's ID
Returns
boolean (opens new window) – Whether the category group was deleted successfully
Throws
- Throwable (opens new window)
if reasons
# fillGapsInCategories()
DEPRECATED
Deprecated in 3.6.0. Use craft\services\Structures::fillGapsInElements() instead.
Patches an array of categories, filling in any gaps in the tree.
View source (opens new window)
Arguments
$categories
(craft\elements\Category[])
# getAllGroupIds()
Returns all of the group IDs.
View source (opens new window)
Returns
# getAllGroups()
Returns all category groups.
View source (opens new window)
Returns
# getCategoryById()
Returns a category by its ID.
View source (opens new window)
Arguments
$categoryId
(integer (opens new window))$siteId
(integer (opens new window), integer (opens new window)[], string (opens new window), null (opens new window))$criteria
(array (opens new window))
Returns
craft\elements\Category, null (opens new window)
# getEditableGroupIds()
Returns all of the category group IDs that are editable by the current user.
View source (opens new window)
Returns
# getEditableGroups()
Returns all editable groups.
View source (opens new window)
Returns
# getGroupByHandle()
Returns a group by its handle.
View source (opens new window)
Arguments
$groupHandle
(string (opens new window))$withTrashed
(boolean (opens new window))
Returns
craft\models\CategoryGroup, null (opens new window)
# getGroupById()
Returns a group by its ID.
View source (opens new window)
Arguments
$groupId
(integer (opens new window))
Returns
craft\models\CategoryGroup, null (opens new window)
# getGroupByUid()
- Since
- 3.1.0
Returns a group by its UID.
View source (opens new window)
Arguments
$uid
(string (opens new window))
Returns
craft\models\CategoryGroup, null (opens new window)
# getGroupSiteSettings()
Returns a group's site settings.
View source (opens new window)
Arguments
$groupId
(integer (opens new window))
Returns
craft\models\CategoryGroup_SiteSettings[]
# getTotalGroups()
Gets the total number of category groups.
View source (opens new window)
Returns
# handleChangedCategoryGroup()
Handle category group change
View source (opens new window)
Arguments
$event
(craft\events\ConfigEvent)
# handleDeletedCategoryGroup()
Handle Category group getting deleted
View source (opens new window)
Arguments
$event
(craft\events\ConfigEvent)
# isGroupTemplateValid()
Returns whether a group’s categories have URLs for the given site ID, and if the group’s template path is valid.
View source (opens new window)
Arguments
$group
(craft\models\CategoryGroup)$siteId
(integer (opens new window))
Returns
# pruneDeletedField()
DEPRECATED
Deprecated in 4.0.5. Unused fields will be pruned automatically as field layouts are resaved.
View source (opens new window)
# pruneDeletedSite()
Prune a deleted site from category group site settings.
View source (opens new window)
Arguments
$event
(craft\events\DeleteSiteEvent)
# saveGroup()
Saves a category group.
View source (opens new window)
Arguments
$group
(craft\models\CategoryGroup) – The category group to be saved$runValidation
(boolean (opens new window)) – Whether the category group should be validated
Returns
boolean (opens new window) – Whether the category group was saved successfully
Throws
- craft\errors\CategoryGroupNotFoundException
if $group has an invalid ID - Throwable (opens new window)
if reasons
# Events
# EVENT_AFTER_DELETE_GROUP
The event that is triggered after a category group is deleted.
# EVENT_AFTER_SAVE_GROUP
The event that is triggered after a category group is saved.
# EVENT_BEFORE_APPLY_GROUP_DELETE
- Type
- craft\events\CategoryGroupEvent
- Since
- 3.1.0
The event that is triggered before a category group delete is applied to the database.
# EVENT_BEFORE_DELETE_GROUP
The event that is triggered before a category group is deleted.
# EVENT_BEFORE_SAVE_GROUP
The event that is triggered before a category group is saved.