Class craft\services\Categories
- Inheritance
- craft\services\Categories » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Available since version
- 3.0
- Source Code
- https://github.com/craftcms/cms/blob/master/src/services/Categories.php
Categories service.
An instance of the Categories service is globally accessible in Craft via Craft::$app->categories
.
Method | Description | Defined By |
---|---|---|
__call() |
Calls the named method which is not a class method. | yii\base\BaseObject |
__clone() |
This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() |
Constructor. | yii\base\BaseObject |
__get() |
Returns the value of an object property. | yii\base\BaseObject |
__isset() |
Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() |
Sets value of an object property. | yii\base\BaseObject |
__unset() |
Sets an object property to null. | yii\base\BaseObject |
applyBranchLimitToCategories() |
Filters an array of categories down to only <= X branches. | craft\services\Categories |
attachBehavior() |
Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() |
Attaches a list of behaviors to the component. | yii\base\Component |
behaviors() |
Returns a list of behaviors that this component should behave as. | yii\base\Component |
canGetProperty() |
Returns a value indicating whether a property can be read. | yii\base\BaseObject |
canSetProperty() |
Returns a value indicating whether a property can be set. | yii\base\BaseObject |
className() |
Returns the fully qualified name of this class. | yii\base\BaseObject |
deleteGroupById() |
Deletes a category group by its ID. | craft\services\Categories |
detachBehavior() |
Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() |
Detaches all behaviors from the component. | yii\base\Component |
ensureBehaviors() |
Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
fillGapsInCategories() |
Patches an array of categories, filling in any gaps in the tree. | craft\services\Categories |
getAllGroupIds() |
Returns all of the group IDs. | craft\services\Categories |
getAllGroups() |
Returns all category groups. | craft\services\Categories |
getBehavior() |
Returns the named behavior object. | yii\base\Component |
getBehaviors() |
Returns all behaviors attached to this component. | yii\base\Component |
getCategoryById() |
Returns a category by its ID. | craft\services\Categories |
getEditableGroupIds() |
Returns all of the category group IDs that are editable by the current user. | craft\services\Categories |
getEditableGroups() |
Returns all editable groups. | craft\services\Categories |
getGroupByHandle() |
Returns a group by its handle. | craft\services\Categories |
getGroupById() |
Returns a group by its ID. | craft\services\Categories |
getGroupSiteSettings() |
Returns a group's site settings. | craft\services\Categories |
getTotalGroups() |
Gets the total number of category groups. | craft\services\Categories |
hasEventHandlers() |
Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() |
Returns a value indicating whether a method is defined. | yii\base\BaseObject |
hasProperty() |
Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() |
Initializes the object. | yii\base\BaseObject |
isGroupTemplateValid() |
Returns whether a group’s categories have URLs for the given site ID, and if the group’s template path is valid. | craft\services\Categories |
off() |
Detaches an existing event handler from this component. | yii\base\Component |
on() |
Attaches an event handler to an event. | yii\base\Component |
saveGroup() |
Saves a category group. | craft\services\Categories |
trigger() |
Triggers an event. | yii\base\Component |
Event | Type | Description | Defined By |
---|---|---|---|
EVENT_AFTER_DELETE_GROUP |
craft\events\CategoryGroupEvent | The event that is triggered after a category group is deleted. | craft\services\Categories |
EVENT_AFTER_SAVE_GROUP |
craft\events\CategoryGroupEvent | The event that is triggered after a category group is saved. | craft\services\Categories |
EVENT_BEFORE_DELETE_GROUP |
craft\events\CategoryGroupEvent | The event that is triggered before a category group is deleted. | craft\services\Categories |
EVENT_BEFORE_SAVE_GROUP |
craft\events\CategoryGroupEvent | The event that is triggered before a category group is saved. | craft\services\Categories |
Method Details
applyBranchLimitToCategories()
public method
#
Filters an array of categories down to only <= X branches.
public void applyBranchLimitToCategories ( array &$categories, \craft\services\int $branchLimit )
$categories |
craft\elements\Category[] | |
$branchLimit |
integer |
deleteGroupById()
public method
#
Deletes a category group by its ID.
public boolean deleteGroupById ( \craft\services\int $groupId )
$groupId |
integer | |
return | boolean | Whether the category group was deleted successfully |
---|---|---|
throws | Throwable | if reasons |
fillGapsInCategories()
public method
#
Patches an array of categories, filling in any gaps in the tree.
public void fillGapsInCategories ( array &$categories )
$categories |
craft\elements\Category[] |
getAllGroupIds()
public method
#
Returns all of the group IDs.
public integer[] getAllGroupIds ( )
getAllGroups()
public method
#
Returns all category groups.
public craft\models\CategoryGroup[] getAllGroups ( )
getCategoryById()
public method
#
Returns a category by its ID.
public craft\elements\Category, null getCategoryById ( \craft\services\int $categoryId, \craft\services\int $siteId = null )
$categoryId |
integer | |
$siteId |
integer, null |
getEditableGroupIds()
public method
#
Returns all of the category group IDs that are editable by the current user.
public integer[] getEditableGroupIds ( )
getEditableGroups()
public method
#
Returns all editable groups.
public craft\models\CategoryGroup[] getEditableGroups ( )
getGroupByHandle()
public method
#
Returns a group by its handle.
public craft\models\CategoryGroup, null getGroupByHandle ( \craft\services\string $groupHandle )
$groupHandle |
string |
getGroupById()
public method
#
Returns a group by its ID.
public craft\models\CategoryGroup, null getGroupById ( \craft\services\int $groupId )
$groupId |
integer |
getGroupSiteSettings()
public method
#
Returns a group's site settings.
public craft\models\CategoryGroup_SiteSettings[] getGroupSiteSettings ( \craft\services\int $groupId )
$groupId |
integer |
getTotalGroups()
public method
#
Gets the total number of category groups.
public integer getTotalGroups ( )
isGroupTemplateValid()
public method
#
Returns whether a group’s categories have URLs for the given site ID, and if the group’s template path is valid.
public boolean isGroupTemplateValid ( craft\models\CategoryGroup $group, \craft\services\int $siteId )
$group |
craft\models\CategoryGroup | |
$siteId |
integer |
saveGroup()
public method
#
Saves a category group.
public boolean saveGroup ( craft\models\CategoryGroup $group, \craft\services\bool $runValidation = true )
$group |
craft\models\CategoryGroup | The category group to be saved |
$runValidation |
boolean | Whether the category group should be validated |
return | boolean | Whether the category group was saved successfully |
---|---|---|
throws | craft\errors\CategoryGroupNotFoundException | if $group has an invalid ID |
throws | Throwable | if reasons |
Event Details
EVENT_AFTER_DELETE_GROUP
event of type craft\events\CategoryGroupEvent
#
The event that is triggered after a category group is deleted.
EVENT_AFTER_SAVE_GROUP
event of type craft\events\CategoryGroupEvent
#
The event that is triggered after a category group is saved.
EVENT_BEFORE_DELETE_GROUP
event of type craft\events\CategoryGroupEvent
#
The event that is triggered before a category group is deleted.
EVENT_BEFORE_SAVE_GROUP
event of type craft\events\CategoryGroupEvent
#
The event that is triggered before a category group is saved.