Sections

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

Sections service.

An instance of the Sections service is globally accessible in Craft via Craft::$app->sections.

View source

Public Properties

PropertyDescription
$allSectionIdsinteger[] – All the sections’ IDs.
$allSectionscraft\models\Section[] – All the sections.
$behaviorsyii\base\Behavior – List of behaviors attached to this component
$editableSectionIdsarray – All the editable sections’ IDs.
$editableSectionscraft\models\Section[] – All the editable sections.
$totalEditableSectionsinteger
$totalSectionsinteger

$allSectionIds

Type
integer[]
Access
Read-only

All the sections’ IDs.

View source

Signature

public integer[] getAllSectionIds ( )

$allSections

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

All the sections.

View source

Signature

public craft\models\Section[] getAllSections ( )

$editableSectionIds

Type
array
Access
Read-only

All the editable sections’ IDs.

View source

Signature

public array getEditableSectionIds ( )

$editableSections

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

All the editable sections.

View source

Signature

public craft\models\Section[] getEditableSections ( )

$totalEditableSections

Type
integer
Access
Read-only

View source

Signature

public integer getTotalEditableSections ( )

$totalSections

Type
integer
Access
Read-only

View source

Signature

public integer getTotalSections ( )

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.
deleteEntryType()Deletes an entry type.
deleteEntryTypeById()Deletes an entry type by its ID.
deleteSection()Deletes a section.
deleteSectionById()Deletes a section 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.
getAllSectionIds()Returns all of the section IDs.
getAllSections()Returns all sections.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getEditableSectionIds()Returns all of the section IDs that are editable by the current user.
getEditableSections()Returns all editable sections.
getEntryTypeById()Returns an entry type by its ID.
getEntryTypesByHandle()Returns entry types that have a given handle.
getEntryTypesBySectionId()Returns a section’s entry types.
getSectionByHandle()Gets a section by its handle.
getSectionById()Returns a section by its ID.
getSectionSiteSettings()Returns a section’s site-specific settings.
getSectionsByType()Returns all sections of a given type.
getTotalEditableSections()Gets the total number of sections that are editable by the current user.
getTotalSections()Gets the total number of sections.
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.
isSectionTemplateValid()Returns whether a section’s entries have URLs for the given site ID, and if the section’s template path is valid.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
reorderEntryTypes()Reorders entry types.
saveEntryType()Saves an entry type.
saveSection()Saves a section.
trigger()Triggers an event.

deleteEntryType()

Deletes an entry type.

View source

Arguments

Returns

boolean – Whether the entry type was deleted successfully

Throws

Signature

public boolean deleteEntryType ( craft\models\EntryType $entryType )

Example

deleteEntryTypeById()

Deletes an entry type by its ID.

View source

Arguments

Returns

boolean – Whether the entry type was deleted successfully

Throws

Signature

public boolean deleteEntryTypeById ( \craft\services\int $entryTypeId )

Example

deleteSection()

Deletes a section.

View source

Arguments

Returns

boolean – Whether the section was deleted successfully

Throws

Signature

public boolean deleteSection ( craft\models\Section $section )

Example

deleteSectionById()

Deletes a section by its ID.

View source

Arguments

Returns

boolean – Whether the section was deleted successfully

Throws

Signature

public boolean deleteSectionById ( \craft\services\int $sectionId )

Example

getAllSectionIds()

Returns all of the section IDs.

View source

Returns

integer[] – All the sections’ IDs.

Signature

public integer[] getAllSectionIds ( )

Example

getAllSections()

Returns all sections.

View source

Returns

craft\models\Section[] – All the sections.

Signature

public craft\models\Section[] getAllSections ( )

Example

getEditableSectionIds()

Returns all of the section IDs that are editable by the current user.

View source

Returns

array – All the editable sections’ IDs.

Signature

public array getEditableSectionIds ( )

Example

getEditableSections()

Returns all editable sections.

View source

Returns

craft\models\Section[] – All the editable sections.

Signature

public craft\models\Section[] getEditableSections ( )

Example

getEntryTypeById()

Returns an entry type by its ID.

View source

Arguments

Returns

craft\models\EntryType, null

Signature

public craft\models\EntryType, null getEntryTypeById ( \craft\services\int $entryTypeId )

Example

getEntryTypesByHandle()

Returns entry types that have a given handle.

View source

Arguments

Returns

craft\models\EntryType[]

Signature

public craft\models\EntryType[] getEntryTypesByHandle ( \craft\services\string $entryTypeHandle )

Example

getEntryTypesBySectionId()

Returns a section’s entry types.

View source

Arguments

Returns

craft\models\EntryType[]

Signature

public craft\models\EntryType[] getEntryTypesBySectionId ( \craft\services\int $sectionId )

Example

getSectionByHandle()

Gets a section by its handle.

View source

Arguments

Returns

craft\models\Section, null

Signature

public craft\models\Section, null getSectionByHandle ( \craft\services\string $sectionHandle )

Example

getSectionById()

Returns a section by its ID.

View source

Arguments

Returns

craft\models\Section, null

Signature

public craft\models\Section, null getSectionById ( \craft\services\int $sectionId )

Example

getSectionSiteSettings()

Returns a section’s site-specific settings.

View source

Arguments

Returns

craft\models\Section_SiteSettings[] – The section’s site-specific settings.

Signature

public craft\models\Section_SiteSettings[] getSectionSiteSettings ( \craft\services\int $sectionId )

getSectionsByType()

Returns all sections of a given type.

View source

Arguments

  • $type (string) – The section type (single, channel, or structure)

Returns

craft\models\Section[] – All the sections of the given type.

Signature

public craft\models\Section[] getSectionsByType ( \craft\services\string $type )

Example

getTotalEditableSections()

Gets the total number of sections that are editable by the current user.

View source

Returns

integer

Signature

public integer getTotalEditableSections ( )

Example

getTotalSections()

Gets the total number of sections.

View source

Returns

integer

Signature

public integer getTotalSections ( )

Example

isSectionTemplateValid()

Returns whether a section’s entries have URLs for the given site ID, and if the section’s template path is valid.

View source

Arguments

Returns

boolean

Signature

public boolean isSectionTemplateValid ( craft\models\Section $section, \craft\services\int $siteId )

reorderEntryTypes()

Reorders entry types.

View source

Arguments

Returns

boolean – Whether the entry types were reordered successfully

Throws

Signature

public boolean reorderEntryTypes ( array $entryTypeIds )

saveEntryType()

Saves an entry type.

View source

Arguments

Returns

boolean – Whether the entry type was saved successfully

Throws

Signature

public boolean saveEntryType ( craft\models\EntryType $entryType, \craft\services\bool $runValidation = true )

saveSection()

Saves a section.

View source

Arguments

Returns

boolean

Throws

Signature

public boolean saveSection ( craft\models\Section $section, \craft\services\bool $runValidation = true )

Example

Events

EVENT_AFTER_DELETE_ENTRY_TYPE

Type
craft\events\EntryTypeEvent

The event that is triggered after an entry type is deleted.

EVENT_AFTER_DELETE_SECTION

Type
craft\events\SectionEvent

The event that is triggered after a section is deleted.

EVENT_AFTER_SAVE_ENTRY_TYPE

Type
craft\events\EntryTypeEvent

The event that is triggered after an entry type is saved.

EVENT_AFTER_SAVE_SECTION

Type
craft\events\SectionEvent

The event that is triggered after a section is saved.

EVENT_BEFORE_DELETE_ENTRY_TYPE

Type
craft\events\EntryTypeEvent

The event that is triggered before an entry type is deleted.

EVENT_BEFORE_DELETE_SECTION

Type
craft\events\SectionEvent

The event that is triggered before a section is deleted.

EVENT_BEFORE_SAVE_ENTRY_TYPE

Type
craft\events\EntryTypeEvent

The event that is triggered before an entry type is saved.

EVENT_BEFORE_SAVE_SECTION

Type
craft\events\SectionEvent

The event that is triggered before a section is saved.