Class craft\services\Sections
- Inheritance
- craft\services\Sections » 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/Sections.php
Sections service.
An instance of the Sections service is globally accessible in Craft via Craft::$app->sections
.
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 |
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 |
deleteEntryType() |
Deletes an entry type. | craft\services\Sections |
deleteEntryTypeById() |
Deletes an entry type by its ID. | craft\services\Sections |
deleteSection() |
Deletes a section. | craft\services\Sections |
deleteSectionById() |
Deletes a section by its ID. | craft\services\Sections |
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 |
getAllSectionIds() |
Returns all of the section IDs. | craft\services\Sections |
getAllSections() |
Returns all sections. | craft\services\Sections |
getBehavior() |
Returns the named behavior object. | yii\base\Component |
getBehaviors() |
Returns all behaviors attached to this component. | yii\base\Component |
getEditableSectionIds() |
Returns all of the section IDs that are editable by the current user. | craft\services\Sections |
getEditableSections() |
Returns all editable sections. | craft\services\Sections |
getEntryTypeById() |
Returns an entry type by its ID. | craft\services\Sections |
getEntryTypesByHandle() |
Returns entry types that have a given handle. | craft\services\Sections |
getEntryTypesBySectionId() |
Returns a section’s entry types. | craft\services\Sections |
getSectionByHandle() |
Gets a section by its handle. | craft\services\Sections |
getSectionById() |
Returns a section by its ID. | craft\services\Sections |
getSectionSiteSettings() |
Returns a section’s site-specific settings. | craft\services\Sections |
getSectionsByType() |
Returns all sections of a given type. | craft\services\Sections |
getTotalEditableSections() |
Gets the total number of sections that are editable by the current user. | craft\services\Sections |
getTotalSections() |
Gets the total number of sections. | craft\services\Sections |
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 |
isSectionTemplateValid() |
Returns whether a section’s entries have URLs for the given site ID, and if the section’s template path is valid. | craft\services\Sections |
off() |
Detaches an existing event handler from this component. | yii\base\Component |
on() |
Attaches an event handler to an event. | yii\base\Component |
reorderEntryTypes() |
Reorders entry types. | craft\services\Sections |
saveEntryType() |
Saves an entry type. | craft\services\Sections |
saveSection() |
Saves a section. | craft\services\Sections |
trigger() |
Triggers an event. | yii\base\Component |
Method Details
deleteEntryType()
public method
#
Deletes an entry type.
public boolean deleteEntryType ( craft\models\EntryType $entryType )
$entryType |
craft\models\EntryType | |
return | boolean | Whether the entry type was deleted successfully |
---|---|---|
throws | Throwable | if reasons |
deleteEntryTypeById()
public method
#
Deletes an entry type by its ID.
public boolean deleteEntryTypeById ( \craft\services\int $entryTypeId )
$entryTypeId |
integer | |
return | boolean | Whether the entry type was deleted successfully |
---|---|---|
throws | Throwable | if reasons |
deleteSection()
public method
#
Deletes a section.
public boolean deleteSection ( craft\models\Section $section )
$section |
craft\models\Section | |
return | boolean | Whether the section was deleted successfully |
---|---|---|
throws | Throwable | if reasons |
deleteSectionById()
public method
#
Deletes a section by its ID.
public boolean deleteSectionById ( \craft\services\int $sectionId )
$sectionId |
integer | |
return | boolean | Whether the section was deleted successfully |
---|---|---|
throws | Throwable | if reasons |
getAllSectionIds()
public method
#
Returns all of the section IDs.
public integer[] getAllSectionIds ( )
return | integer[] | All the sections’ IDs. |
---|
getAllSections()
public method
#
Returns all sections.
public craft\models\Section[] getAllSections ( )
return | craft\models\Section[] | All the sections. |
---|
getEditableSectionIds()
public method
#
Returns all of the section IDs that are editable by the current user.
public array getEditableSectionIds ( )
return | array | All the editable sections’ IDs. |
---|
getEditableSections()
public method
#
Returns all editable sections.
public craft\models\Section[] getEditableSections ( )
return | craft\models\Section[] | All the editable sections. |
---|
getEntryTypeById()
public method
#
Returns an entry type by its ID.
public craft\models\EntryType, null getEntryTypeById ( \craft\services\int $entryTypeId )
$entryTypeId |
integer |
getEntryTypesByHandle()
public method
#
Returns entry types that have a given handle.
public craft\models\EntryType[] getEntryTypesByHandle ( \craft\services\string $entryTypeHandle )
$entryTypeHandle |
string |
getEntryTypesBySectionId()
public method
#
Returns a section’s entry types.
public craft\models\EntryType[] getEntryTypesBySectionId ( \craft\services\int $sectionId )
$sectionId |
integer |
getSectionByHandle()
public method
#
Gets a section by its handle.
public craft\models\Section, null getSectionByHandle ( \craft\services\string $sectionHandle )
$sectionHandle |
string |
getSectionById()
public method
#
Returns a section by its ID.
public craft\models\Section, null getSectionById ( \craft\services\int $sectionId )
$sectionId |
integer |
getSectionSiteSettings()
public method
#
Returns a section’s site-specific settings.
public craft\models\Section_SiteSettings[] getSectionSiteSettings ( \craft\services\int $sectionId )
$sectionId |
integer | |
return | craft\models\Section_SiteSettings[] | The section’s site-specific settings. |
---|
getSectionsByType()
public method
#
Returns all sections of a given type.
public craft\models\Section[] getSectionsByType ( \craft\services\string $type )
$type |
string | |
return | craft\models\Section[] | All the sections of the given type. |
---|
getTotalEditableSections()
public method
#
Gets the total number of sections that are editable by the current user.
public integer getTotalEditableSections ( )
getTotalSections()
public method
#
Gets the total number of sections.
public integer getTotalSections ( )
isSectionTemplateValid()
public method
#
Returns whether a section’s entries have URLs for the given site ID, and if the section’s template path is valid.
public boolean isSectionTemplateValid ( craft\models\Section $section, \craft\services\int $siteId )
$section |
craft\models\Section | |
$siteId |
integer |
reorderEntryTypes()
public method
#
Reorders entry types.
public boolean reorderEntryTypes ( array $entryTypeIds )
$entryTypeIds |
array | |
return | boolean | Whether the entry types were reordered successfully |
---|---|---|
throws | Throwable | if reasons |
saveEntryType()
public method
#
Saves an entry type.
public boolean saveEntryType ( craft\models\EntryType $entryType, \craft\services\bool $runValidation = true )
$entryType |
craft\models\EntryType | The entry type to be saved |
$runValidation |
boolean | Whether the entry type should be validated |
return | boolean | Whether the entry type was saved successfully |
---|---|---|
throws | craft\errors\EntryTypeNotFoundException | if $entryType->id is invalid |
throws | Throwable | if reasons |
saveSection()
public method
#
Saves a section.
use craft\models\Section;
use craft\models\Section_SiteSettings;
$section = new Section([
'name' => 'News',
'handle' => 'news',
'type' => Section::TYPE_CHANNEL,
'siteSettings' => [
new Section_SiteSettings([
'siteId' => Craft::$app->sites->getPrimarySite()->id,
'enabledByDefault' => true,
'hasUrls' => true,
'uriFormat' => 'foo/{slug}',
'template' => 'foo/_entry',
]),
]
]);
$success = Craft::$app->sections->saveSection($section);
public boolean saveSection ( craft\models\Section $section, \craft\services\bool $runValidation = true )
$section |
craft\models\Section | The section to be saved |
$runValidation |
boolean | Whether the section should be validated |
throws | craft\errors\SectionNotFoundException | if $section->id is invalid |
---|---|---|
throws | Throwable | if reasons |
Event Details
EVENT_AFTER_DELETE_ENTRY_TYPE
event of type craft\events\EntryTypeEvent
#
The event that is triggered after an entry type is deleted.
EVENT_AFTER_DELETE_SECTION
event of type craft\events\SectionEvent
#
The event that is triggered after a section is deleted.
EVENT_AFTER_SAVE_ENTRY_TYPE
event of type craft\events\EntryTypeEvent
#
The event that is triggered after an entry type is saved.
EVENT_AFTER_SAVE_SECTION
event of type craft\events\SectionEvent
#
The event that is triggered after a section is saved.
EVENT_BEFORE_DELETE_ENTRY_TYPE
event of type craft\events\EntryTypeEvent
#
The event that is triggered before an entry type is deleted.
EVENT_BEFORE_DELETE_SECTION
event of type craft\events\SectionEvent
#
The event that is triggered before a section is deleted.
EVENT_BEFORE_SAVE_ENTRY_TYPE
event of type craft\events\EntryTypeEvent
#
The event that is triggered before an entry type is saved.
EVENT_BEFORE_SAVE_SECTION
event of type craft\events\SectionEvent
#
The event that is triggered before a section is saved.