Craft 3 Class Reference

Class craft\services\Structures

Inheritance
craft\services\Structures » 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/Structures.php

Structures service.

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

Public Methods
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
append() Appends an element to another within a given structure. craft\services\Structures
appendToRoot() Appends an element to the root of a given structure. craft\services\Structures
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
deleteStructureById() Deletes a structure by its ID. craft\services\Structures
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
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getElementLevelDelta() Returns the descendant level delta for a given element. craft\services\Structures
getStructureById() Returns a structure by its ID. craft\services\Structures
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
moveAfter() Moves an element after another within a given structure. craft\services\Structures
moveBefore() Moves an element before another within a given structure. craft\services\Structures
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
prepend() Prepends an element to another within a given structure. craft\services\Structures
prependToRoot() Prepends an element to the root of a given structure. craft\services\Structures
saveStructure() Saves a structure craft\services\Structures
trigger() Triggers an event. yii\base\Component
Events
Event Type Description Defined By
EVENT_AFTER_MOVE_ELEMENT craft\events\MoveElementEvent The event that is triggered after an element is moved. craft\services\Structures
EVENT_BEFORE_MOVE_ELEMENT craft\events\MoveElementEvent The event that is triggered before an element is moved. craft\services\Structures

Method Details

append() public method #

Appends an element to another within a given structure.

public boolean append ( \craft\services\int $structureId, craft\base\ElementInterface $element, craft\base\ElementInterface $parentElement, \craft\services\string $mode 'auto' )
$structureId integer
$element craft\base\ElementInterface
$parentElement craft\base\ElementInterface
$mode string Whether this is an "insert", "update", or "auto".
throws yii\base\Exception

appendToRoot() public method #

Appends an element to the root of a given structure.

public boolean appendToRoot ( \craft\services\int $structureId, craft\base\ElementInterface $element, \craft\services\string $mode 'auto' )
$structureId integer
$element craft\base\ElementInterface
$mode string Whether this is an "insert", "update", or "auto".
throws yii\base\Exception

deleteStructureById() public method #

Deletes a structure by its ID.

public boolean deleteStructureById ( \craft\services\int $structureId )
$structureId integer

getElementLevelDelta() public method #

Returns the descendant level delta for a given element.

public integer getElementLevelDelta ( \craft\services\int $structureId, craft\base\ElementInterface $element )
$structureId integer
$element craft\base\ElementInterface

getStructureById() public method #

Returns a structure by its ID.

public craft\models\Structure, null getStructureById ( \craft\services\int $structureId )
$structureId integer

moveAfter() public method #

Moves an element after another within a given structure.

public boolean moveAfter ( \craft\services\int $structureId, craft\base\ElementInterface $element, craft\base\ElementInterface $prevElement, \craft\services\string $mode 'auto' )
$structureId integer
$element craft\base\ElementInterface
$prevElement craft\base\ElementInterface
$mode string Whether this is an "insert", "update", or "auto".
throws yii\base\Exception

moveBefore() public method #

Moves an element before another within a given structure.

public boolean moveBefore ( \craft\services\int $structureId, craft\base\ElementInterface $element, craft\base\ElementInterface $nextElement, \craft\services\string $mode 'auto' )
$structureId integer
$element craft\base\ElementInterface
$nextElement craft\base\ElementInterface
$mode string Whether this is an "insert", "update", or "auto".
throws yii\base\Exception

prepend() public method #

Prepends an element to another within a given structure.

public boolean prepend ( \craft\services\int $structureId, craft\base\ElementInterface $element, craft\base\ElementInterface $parentElement, \craft\services\string $mode 'auto' )
$structureId integer
$element craft\base\ElementInterface
$parentElement craft\base\ElementInterface
$mode string Whether this is an "insert", "update", or "auto".
throws yii\base\Exception

prependToRoot() public method #

Prepends an element to the root of a given structure.

public boolean prependToRoot ( \craft\services\int $structureId, craft\base\ElementInterface $element, \craft\services\string $mode 'auto' )
$structureId integer
$element craft\base\ElementInterface
$mode string Whether this is an "insert", "update", or "auto".
throws yii\base\Exception

saveStructure() public method #

Saves a structure

public boolean saveStructure ( craft\models\Structure $structure )
$structure craft\models\Structure
return boolean Whether the structure was saved successfully
throws craft\errors\StructureNotFoundException if $structure->id is invalid

Event Details

EVENT_AFTER_MOVE_ELEMENT event of type craft\events\MoveElementEvent #

The event that is triggered after an element is moved.

EVENT_BEFORE_MOVE_ELEMENT event of type craft\events\MoveElementEvent #

The event that is triggered before an element is moved.