Class luya\cms\menu\Item

Inheritanceluya\cms\menu\Item » yii\base\BaseObject
Implementsluya\web\LinkInterface, yii\base\Arrayable, yii\base\Configurable
Uses Traitsluya\web\LinkTrait, yii\base\ArrayableTrait
Available since version1.0.0
Source Code https://github.com/luyadev/luya-module-cms/blob/master/src/menu/Item.php

Menu item Object.

Each menu itaration will return in an Item-Object. The Item-Object contains several methods like returning title, url and ids or retrieve depending item iterations like parents or childs. As the Item Object extends the {{yii\base\BaseObject}} all getter methods can be access as property.

Read more in the [[app-menu.md]] Guide.

Public Properties

Hide inherited properties

Property Type Description Defined By
$alias string Returns the alias name of this page. luya\cms\menu\Item
$children luya\cms\menu\QueryIteratorFilter Get all children of the current item. luya\cms\menu\Item
$container string Returns the container name. luya\cms\menu\Item
$dateCreated integer Returns an unix timestamp when the page was created. luya\cms\menu\Item
$dateUpdated integer Returns an unix timestamp when the page was last time updated. luya\cms\menu\Item
$depth integer Returns the depth of the navigation tree start with 1. luya\cms\menu\Item
$descendants luya\cms\menu\QueryIteratorFilter Get all childrens with childrens children. luya\cms\menu\Item
$description string Returns the page description (used for making meta key description). luya\cms\menu\Item
$hasChildren boolean Check whether an item has childrens or not returning a boolean value. luya\cms\menu\Item
$hasParent boolean Check whether the parent has items or not. luya\cms\menu\Item
$href string Returns the href string which can be either with or without domain. luya\cms\menu\Item
$id integer Returns Unique identifier of item, represents data record of cms_nav_item table. luya\cms\menu\Item
$image luya\admin\image\Item|boolean The Image object or false if no image has been uploaded luya\cms\menu\Item
$is404Page boolean This property indicates whether the item is the 404 page item or not. luya\cms\menu\Item
$isActive boolean Returns a boolean value whether the current item is an active link or not, this is also for all parent elements. luya\cms\menu\Item
$isHidden boolean Returns boolean state of visbility. luya\cms\menu\Item
$isHome boolean Returns true if the item is the home item, otherwise false. luya\cms\menu\Item
$isStrictParsing boolean luya\cms\menu\Item
$itemArray array The item property containing the informations with key value parinings. luya\cms\menu\Item
$keywords array Returns an array of user defined keywords for this page (user to generate meta keywords) luya\cms\menu\Item
$lang string|null Can contain the language context, so the sub querys for this item will be the same language context as the parent object which created this object. luya\cms\menu\Item
$model luya\cms\models\Nav|boolean Returns the {{\luya\cms\models\Nav}} object for the current navigation item. luya\cms\menu\Item
$moduleName string Returns the name of the module if its of type module(2) luya\cms\menu\Item
$navId integer Returns the Navigation Id which is not unique but is used for the menu tree luya\cms\menu\Item
$nextSibling luya\cms\menu\Item|boolean Returns the next sibling based on the current sibling, if not found false is returned. luya\cms\menu\Item
$parent luya\cms\menu\Item Returns a Item-Object of the parent element, if no parent element exists returns false. luya\cms\menu\Item
$parentNavId integer Returns the parent navigation id of this item (0 = root level). luya\cms\menu\Item
$parents luya\cms\menu\QueryIteratorFilter Return all parent elements without the current item. luya\cms\menu\Item
$prevSibling luya\cms\menu\Item|boolean Returns the previous sibling based on the current sibling, if not found false is returned. luya\cms\menu\Item
$seoTitle string Returns the Alternative SEO-Title. luya\cms\menu\Item
$sibilings luya\cms\menu\QueryIteratorFilter Get all sibilings for the current item, this also includes the current item iteself. luya\cms\menu\Item
$siblings luya\cms\menu\QueryIteratorFilter An array with all item-object siblings luya\cms\menu\Item
$sortIndex integer Sort index position for the current siblings list. luya\cms\menu\Item
$target string Returns the target string value for the link resource. luya\cms\menu\Item
$teardown luya\cms\menu\QueryIteratorFilter Return all parent elemtns with the current item. luya\cms\menu\Item
$title string Returns the title of this page luya\cms\menu\Item
$type integer Returns the type of page 1=Page with blocks, 2=Module, 3=Redirect luya\cms\menu\Item
$userCreated luya\admin\models\User Returns an active record object for the admin user who created this page. luya\cms\menu\Item
$userUpdated luya\admin\models\User Returns an active record object for the admin user who last time updated this page. luya\cms\menu\Item

Public Methods

Hide inherited methods

Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__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
__toString() Return the href string from getHref() when echoing the object. luya\web\LinkTrait
__unset() Sets an object property to null. yii\base\BaseObject
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
down() Go down to a given element which is evalutaed trough a callable. luya\cms\menu\Item
extraFields() Returns the list of fields that can be expanded further and returned by toArray(). yii\base\ArrayableTrait
fields() Returns the list of fields that should be returned by default by toArray() when no specific fields are specified. luya\cms\menu\Item
getAbsoluteLink() Returns the link with an absolute scheme. luya\cms\menu\Item
getAlias() Returns the current alias name of the item (identifier for the url) also (& previous) called rewrite. luya\cms\menu\Item
getChildren() Get all children of the current item. Children means going the depth/menulevel down e.g. from 1 to 2. luya\cms\menu\Item
getContainer() Return the current container name of this item. luya\cms\menu\Item
getDateCreated() Returns an unix timestamp when the page was created. luya\cms\menu\Item
getDateUpdated() Returns an unix timestamp when the page was last time updated. luya\cms\menu\Item
getDepth() Returns the depth of the navigation tree start with 1. Also known as menu level. luya\cms\menu\Item
getDescendants() Returns all children and childrens-children. luya\cms\menu\Item
getDescription() Returns the description provided by the cms admin, if any. luya\cms\menu\Item
getHasChildren() Check whether an item has childrens or not returning a boolean value. luya\cms\menu\Item
getHasParent() Check whether the parent has items or not. luya\cms\menu\Item
getHref() Get the href attribute value inside the Link tag. luya\cms\menu\Item
getId() Get the Id of the Item, the Id is an unique identifiere an represents the id column in the cms_nav_item table. luya\cms\menu\Item
getImage() Returns the image object if an object is uploaded. luya\cms\menu\Item
getIsActive() Returns a boolean value whether the current item is an active link or not, this is also for all parent elements. If a child item is active, the parent element is activ as well. luya\cms\menu\Item
getIsHidden() Whether the item is hidden or not if hidden items can be retreived (with/without settings). luya\cms\menu\Item
getIsHome() Whether current item is home or not. luya\cms\menu\Item
getIsStrictParsing() Returns whether the current page has strict parsing mode disabled or not. luya\cms\menu\Item
getKeywords() luya\cms\menu\Item
getLink() Returns the current item link relative path with composition (language). The path is always relativ to the host. luya\cms\menu\Item
getModel() Get the ActiveRecord Model for the current Nav Model. luya\cms\menu\Item
getModuleName() If the type of the item is equals 2 we can detect the module name and returns this information. luya\cms\menu\Item
getNavId() Get the Nav-id of the Item, the Nav-Id is not unique but in case of the language container the nav id is unique. The Nav-Id identifier repersents the id coluumn of the cms_nav table. luya\cms\menu\Item
getNextSibling() Get the next sibling in the current siblings list. luya\cms\menu\Item
getParent() Returns a Item-Object of the parent element, if no parent element exists returns false. luya\cms\menu\Item
getParentNavId() Get the parent_nav_id of the current item. If the current Item-Object belongs to a parent navigation item, the getParentNavId() method returns the getNavId() of the parent item. luya\cms\menu\Item
getParents() Return all parent elements without the current item. luya\cms\menu\Item
getPrevSibling() Get the previous sibling in the current siblings list. luya\cms\menu\Item
getProperty() Get Property Object. luya\cms\menu\Item
getPropertyValue() Get the value of a Property Object. luya\cms\menu\Item
getSeoTitle() Returns the Alternative SEO-Title. luya\cms\menu\Item
getSiblings() Get all sibilings for the current item, this also includes the current item iteself. luya\cms\menu\Item
getSortIndex() Get the sorting index position for the item on the current siblings. luya\cms\menu\Item
getTarget() Get the target attribute value inside the Link tag. luya\cms\menu\Item
getTeardown() Return all parent elements with the current item. luya\cms\menu\Item
getTitle() Returns the current Title of the Menu Item. luya\cms\menu\Item
getType() Return the current nav item type by number. luya\cms\menu\Item
getUserCreated() Returns an active record object for the admin user who created this page. luya\cms\menu\Item
getUserUpdated() Returns an active record object for the admin user who last time updated this page. luya\cms\menu\Item
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() Item-Object initiliazer, verify if the itemArray property is empty. luya\cms\menu\Item
setIsHidden() Override the default hidden state of an item. luya\cms\menu\Item
setModel() Setter method for the Model. luya\cms\menu\Item
setTarget() Setter method for the link target. luya\cms\menu\Item
setTitle() Override the current title of item. luya\cms\menu\Item
toArray() Converts the model into an array. yii\base\ArrayableTrait
with() You can use with() before the following methods: luya\cms\menu\Item
without() Unset a value from the with() method. luya\cms\menu\Item

Protected Methods

Hide inherited methods

Method Description Defined By
extractFieldsFor() Extract nested fields from a fields collection for a given root field Nested fields are separated with dots (.). e.g: "item.id" The previous example would extract "id". yii\base\ArrayableTrait
extractRootFields() Extracts the root field names from nested fields. yii\base\ArrayableTrait
getInternalDescendants() luya\cms\menu\Item
redirectMapData() Internal used to retriev redirect data. luya\cms\menu\Item
resolveFields() Determines which fields can be returned by toArray(). yii\base\ArrayableTrait

Property Details

Hide inherited properties

$alias public property

Returns the alias name of this page.

public string $alias null
$children public property

Get all children of the current item. Children means going the depth/menulevel down e.g. from 1 to 2.

$container public property

Returns the container name.

public string $container null
$dateCreated public property

Returns an unix timestamp when the page was created.

public integer $dateCreated null
$dateUpdated public property

Returns an unix timestamp when the page was last time updated.

public integer $dateUpdated null
$depth public property

Returns the depth of the navigation tree start with 1. Also known as menu level.

public integer $depth null
$descendants public property

Get all childrens with childrens children.

$description public property

Returns the page description (used for making meta key description).

public string $description null
$hasChildren public property

Check whether an item has childrens or not returning a boolean value.

public boolean $hasChildren null
$hasParent public property

Check whether the parent has items or not.

public boolean $hasParent null
$href public read-only property

Returns the href string which can be either with or without domain.

public string getHref ( )
$id public property

Returns Unique identifier of item, represents data record of cms_nav_item table.

public integer $id null
$image public read-only property (available since version 2.0.0)

The Image object or false if no image has been uploaded

$is404Page public property (available since version 2.0.0)

This property indicates whether the item is the 404 page item or not. This status is set by {{luya\cms\Menu::resolveCurrent()}} method and retrieved in the {{luya\cms\frontend\controllers\DefaultController::actionIndex()}} in order to send 404 response header.

public boolean $is404Page false
$isActive public property

Returns a boolean value whether the current item is an active link or not, this is also for all parent elements. If a child item is active, the parent element is activ as well.

public boolean $isActive null
$isHidden public property

Returns boolean state of visbility.

public boolean $isHidden null
$isHome public property

Returns true if the item is the home item, otherwise false.

public boolean $isHome null
$isStrictParsing public read-only property (available since version 2.1.0)
$itemArray public property

The item property containing the informations with key value parinings. This property will be assigned when creating the Item-Object.

public array $itemArray null
$keywords public property

Returns an array of user defined keywords for this page (user to generate meta keywords)

public array $keywords null
$lang public property

Can contain the language context, so the sub querys for this item will be the same language context as the parent object which created this object.

public string|null $lang null
$model public property

Returns the {{\luya\cms\models\Nav}} object for the current navigation item.

$moduleName public property

Returns the name of the module if its of type module(2)

public string $moduleName null
$navId public property

Returns the Navigation Id which is not unique but is used for the menu tree

public integer $navId null
$nextSibling public property

Returns the next sibling based on the current sibling, if not found false is returned.

$parent public property

Returns a Item-Object of the parent element, if no parent element exists returns false.

$parentNavId public property

Returns the parent navigation id of this item (0 = root level).

public integer $parentNavId null
$parents public property

Return all parent elements without the current item.

$prevSibling public property

Returns the previous sibling based on the current sibling, if not found false is returned.

$seoTitle public property

Returns the Alternative SEO-Title. If entry is empty, the $title will returned instead.

public string $seoTitle null
$sibilings public property

Get all sibilings for the current item, this also includes the current item iteself.

$siblings public read-only property

An array with all item-object siblings

$sortIndex public property

Sort index position for the current siblings list.

public integer $sortIndex null
$target public property

Returns the target string value for the link resource.

public string getTarget ( )
public void setTarget ( $target )
$teardown public property

Return all parent elemtns with the current item.

$title public property

Returns the title of this page

public string $title null
$type public property

Returns the type of page 1=Page with blocks, 2=Module, 3=Redirect

public integer $type null
$userCreated public property

Returns an active record object for the admin user who created this page.

$userUpdated public property

Returns an active record object for the admin user who last time updated this page.

Method Details

Hide inherited methods

__call() public method

Defined in: yii\base\BaseObject::__call()

Calls the named method which is not a class method.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

public mixed __call ( $name, $params )
$name string

The method name

$params array

Method parameters

return mixed

The method return value

throws yii\base\UnknownMethodException

when calling unknown method

                public function __call($name, $params)
{
    throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}

            
__construct() public method

Defined in: yii\base\BaseObject::__construct()

Constructor.

The default implementation does two things:

  • Initializes the object with the given configuration $config.
  • Call init().

If this method is overridden in a child class, it is recommended that

  • the last parameter of the constructor is a configuration array, like $config here.
  • call the parent implementation at the end of the constructor.
public void __construct ( $config = [] )
$config array

Name-value pairs that will be used to initialize the object properties

                public function __construct($config = [])
{
    if (!empty($config)) {
        Yii::configure($this, $config);
    }
    $this->init();
}

            
__get() public method

Defined in: yii\base\BaseObject::__get()

Returns the value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $object->property;.

See also __set().

public mixed __get ( $name )
$name string

The property name

return mixed

The property value

throws yii\base\UnknownPropertyException

if the property is not defined

throws yii\base\InvalidCallException

if the property is write-only

                public function __get($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter();
    } elseif (method_exists($this, 'set' . $name)) {
        throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
    }
    throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}

            
__isset() public method

Defined in: yii\base\BaseObject::__isset()

Checks if a property is set, i.e. defined and not null.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing isset($object->property).

Note that if the property is not defined, false will be returned.

See also https://www.php.net/manual/en/function.isset.php.

public boolean __isset ( $name )
$name string

The property name or the event name

return boolean

Whether the named property is set (not null).

                public function __isset($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter() !== null;
    }
    return false;
}

            
__set() public method

Defined in: yii\base\BaseObject::__set()

Sets value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $object->property = $value;.

See also __get().

public void __set ( $name, $value )
$name string

The property name or the event name

$value mixed

The property value

throws yii\base\UnknownPropertyException

if the property is not defined

throws yii\base\InvalidCallException

if the property is read-only

                public function __set($name, $value)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter($value);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
    } else {
        throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
    }
}

            
__toString() public method

Defined in: luya\web\LinkTrait::__toString()

Return the href string from getHref() when echoing the object.

public void __toString ( )

                public function __toString()
{
    return $this->getHref();
}

            
__unset() public method

Defined in: yii\base\BaseObject::__unset()

Sets an object property to null.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($object->property).

Note that if the property is not defined, this method will do nothing. If the property is read-only, it will throw an exception.

See also https://www.php.net/manual/en/function.unset.php.

public void __unset ( $name )
$name string

The property name

throws yii\base\InvalidCallException

if the property is read only.

                public function __unset($name)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter(null);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
    }
}

            
canGetProperty() public method

Defined in: yii\base\BaseObject::canGetProperty()

Returns a value indicating whether a property can be read.

A property is readable if:

  • the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also canSetProperty().

public boolean canGetProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property can be read

                public function canGetProperty($name, $checkVars = true)
{
    return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}

            
canSetProperty() public method

Defined in: yii\base\BaseObject::canSetProperty()

Returns a value indicating whether a property can be set.

A property is writable if:

  • the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also canGetProperty().

public boolean canSetProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property can be written

                public function canSetProperty($name, $checkVars = true)
{
    return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}

            
className() public static method
Deprecated since 2.0.14. On PHP >=5.5, use ::class instead.

Defined in: yii\base\BaseObject::className()

Returns the fully qualified name of this class.

public static string className ( )
return string

The fully qualified name of this class.

                public static function className()
{
    return get_called_class();
}

            
down() public method (available since version 1.0.9)

Go down to a given element which is evalutaed trough a callable.

Iterate trough parent elements until the last.

$item = Yii::$app->menu->current->down(function(Item $item) {
    if ($item->depth == 1) {
        return $item;
    }
});
public luya\cms\menu\Item|mixed|boolean down ( callable $fn )
$fn callable

A function which holds the current iterated item.

return luya\cms\menu\Item|mixed|boolean

If no item has been picked, false is returned otherwise the picked item or any other callable response.

                public function down(callable $fn)
{
    $parent = $this->with($this->_with)->getParent();
    while ($parent) {
        $response = call_user_func_array($fn, [$parent]);
        if ($response) {
            return $response;
        }
        $parent = $parent->with($this->_with)->getParent();
    }
    return false;
}

            
extraFields() public method

Defined in: yii\base\ArrayableTrait::extraFields()

Returns the list of fields that can be expanded further and returned by toArray().

This method is similar to fields() except that the list of fields returned by this method are not returned by default by toArray(). Only when field names to be expanded are explicitly specified when calling toArray(), will their values be exported.

The default implementation returns an empty array.

You may override this method to return a list of expandable fields based on some context information (e.g. the current application user).

See also:

public array extraFields ( )
return array

The list of expandable field names or field definitions. Please refer to fields() on the format of the return value.

                public function extraFields()
{
    return [];
}

            
extractFieldsFor() protected method (available since version 2.0.14)

Defined in: yii\base\ArrayableTrait::extractFieldsFor()

Extract nested fields from a fields collection for a given root field Nested fields are separated with dots (.). e.g: "item.id" The previous example would extract "id".

protected array extractFieldsFor ( array $fields, $rootField )
$fields array

The fields requested for extraction

$rootField string

The root field for which we want to extract the nested fields

return array

Nested fields extracted for the given field

                protected function extractFieldsFor(array $fields, $rootField)
{
    $result = [];
    foreach ($fields as $field) {
        if (0 === strpos($field, "{$rootField}.")) {
            $result[] = preg_replace('/^' . preg_quote($rootField, '/') . '\./i', '', $field);
        }
    }
    return array_unique($result);
}

            
extractRootFields() protected method (available since version 2.0.14)

Defined in: yii\base\ArrayableTrait::extractRootFields()

Extracts the root field names from nested fields.

Nested fields are separated with dots (.). e.g: "item.id" The previous example would extract "item".

protected array extractRootFields ( array $fields )
$fields array

The fields requested for extraction

return array

Root fields extracted from the given nested fields

                protected function extractRootFields(array $fields)
{
    $result = [];
    foreach ($fields as $field) {
        $result[] = current(explode('.', $field, 2));
    }
    if (in_array('*', $result, true)) {
        $result = [];
    }
    return array_unique($result);
}

            
fields() public method

Returns the list of fields that should be returned by default by toArray() when no specific fields are specified.

A field is a named element in the returned array by toArray().

This method should return an array of field names or field definitions. If the former, the field name will be treated as an object property name whose value will be used as the field value. If the latter, the array key should be the field name while the array value should be the corresponding field definition which can be either an object property name or a PHP callable returning the corresponding field value. The signature of the callable should be:

function ($model, $field) {
    // return field value
}

For example, the following code declares four fields:

  • email: the field name is the same as the property name email;
  • firstName and lastName: the field names are firstName and lastName, and their values are obtained from the first_name and last_name properties;
  • fullName: the field name is fullName. Its value is obtained by concatenating first_name and last_name.
return [
    'email',
    'firstName' => 'first_name',
    'lastName' => 'last_name',
    'fullName' => function ($model) {
        return $model->first_name . ' ' . $model->last_name;
    },
];
public array fields ( )
return array

The list of field names or field definitions.

                public function fields()
{
    return ['href', 'target'];
}

            
getAbsoluteLink() public method

Returns the link with an absolute scheme.

The link with an absolute scheme path example https://luya.io/link where link is the output from the {{luya\cms\menu\item::getLink}} method.

public string getAbsoluteLink ( )
return string

The link path with prepand website host https://luya.io/home/about-us.

getAlias() public method

Returns the current alias name of the item (identifier for the url) also (& previous) called rewrite.

public string getAlias ( )
return string

E.g. "hello-word"

                public function getAlias()
{
    return $this->itemArray['alias'];
}

            
getChildren() public method

Get all children of the current item. Children means going the depth/menulevel down e.g. from 1 to 2.

public luya\cms\menu\QueryIteratorFilter getChildren ( )
return luya\cms\menu\QueryIteratorFilter

Returns all children

                public function getChildren()
{
    return (new Query())
        ->where(['parent_nav_id' => $this->navId, 'container' => $this->getContainer()])
        ->with($this->_with)
        ->lang($this->lang)
        ->all();
}

            
getContainer() public method

Return the current container name of this item.

public string getContainer ( )
return string

Return alias name of the container

                public function getContainer()
{
    return $this->itemArray['container'];
}

            
getDateCreated() public method

Returns an unix timestamp when the page was created.

public integer getDateCreated ( )
return integer

Unix timestamp

                public function getDateCreated()
{
    return $this->itemArray['timestamp_create'];
}

            
getDateUpdated() public method

Returns an unix timestamp when the page was last time updated.

public integer getDateUpdated ( )
return integer

Unix timestamp

                public function getDateUpdated()
{
    return $this->itemArray['timestamp_update'];
}

            
getDepth() public method

Returns the depth of the navigation tree start with 1. Also known as menu level.

public integer getDepth ( )

                public function getDepth()
{
    return $this->itemArray['depth'];
}

            
getDescendants() public method (available since version 3.1.0)

Returns all children and childrens-children.

public luya\cms\menu\QueryIteratorFilter getDescendants ( )

                public function getDescendants()
{
    return Query::createArrayIterator($this->getInternalDescendants(), $this->lang, array_flip($this->_with), false);
}

            
getDescription() public method

Returns the description provided by the cms admin, if any.

public string getDescription ( )
return string

The description string for this page.

                public function getDescription()
{
    return $this->itemArray['description'];
}

            
getHasChildren() public method

Check whether an item has childrens or not returning a boolean value.

public boolean getHasChildren ( )
return boolean

If there are childrens the method returns true, otherwhise false.

                public function getHasChildren()
{
    return count($this->getChildren()) > 0 ? true : false;
}

            
getHasParent() public method

Check whether the parent has items or not.

public boolean getHasParent ( )

                public function getHasParent()
{
    return (bool) $this->getParent();
}

            
getHref() public method

Get the href attribute value inside the Link tag.

public string getHref ( )
return string

Returns the href string which can be either with or without domain.

                public function getHref()
{
    return $this->getLink();
}

            
getId() public method

Get the Id of the Item, the Id is an unique identifiere an represents the id column in the cms_nav_item table.

public integer getId ( )

                public function getId()
{
    return (int) $this->itemArray['id'];
}

            
getImage() public method (available since version 2.0.0)

Returns the image object if an object is uploaded.

public luya\admin\image\Item|boolean getImage ( )
return luya\admin\image\Item|boolean

The Image object or false if no image has been uploaded

                public function getImage()
{
    return Yii::$app->storage->getImage($this->itemArray['image_id']);
}

            
getInternalDescendants() protected method

protected array getInternalDescendants ( )

                protected function getInternalDescendants()
{
    $childrens = $this->with($this->_with)->getChildren();
    $data = [];
    foreach ($childrens as $child) {
        $data[] = $child;
        $data = array_merge($data, $child->getInternalDescendants());
    }
    return $data;
}

            
getIsActive() public method

Returns a boolean value whether the current item is an active link or not, this is also for all parent elements. If a child item is active, the parent element is activ as well.

public boolean getIsActive ( )

                public function getIsActive()
{
    return in_array($this->id, Yii::$app->menu->current->teardown->column('id'));
}

            
getIsHidden() public method

Whether the item is hidden or not if hidden items can be retreived (with/without settings).

public boolean getIsHidden ( )

                public function getIsHidden()
{
    return (bool) $this->itemArray['is_hidden'];
}

            
getIsHome() public method

Whether current item is home or not.

public boolean getIsHome ( )
return boolean

Returns true if the item is the home item, otherwise false.

                public function getIsHome()
{
    return (bool) $this->itemArray['is_home'];
}

            
getIsStrictParsing() public method (available since version 2.1.0)

Returns whether the current page has strict parsing mode disabled or not.

public boolean getIsStrictParsing ( )

                public function getIsStrictParsing()
{
    return !$this->itemArray['is_url_strict_parsing_disabled'];
}

            
getKeywords() public method

public array getKeywords ( )
return array

An array with all keywords for this page

                public function getKeywords()
{
    if ($this->_keywords === null) {
        if (empty($this->itemArray['keywords'])) {
            $this->_keywords = [];
        } else {
            foreach (explode($this->_delimiters[0], str_replace($this->_delimiters, $this->_delimiters[0], $this->itemArray['keywords'])) as $name) {
                if (!empty(trim($name))) {
                    $this->_keywords[] = trim($name);
                }
            }
        }
    }
    return $this->_keywords;
}

            
getLink() public method

Returns the current item link relative path with composition (language). The path is always relativ to the host.

Hidden links will be returned from getLink. So if you make a link from a page to a hidden page, the link of the hidden page will be returned and the link will be successfully displayed

public string getLink ( )
return string

The link path /home/about-us or with composition /de/home/about-us

getModel() public method

Get the ActiveRecord Model for the current Nav Model.

public luya\cms\models\Nav getModel ( )
return luya\cms\models\Nav

Returns the {{\luya\cms\models\Nav}} object for the current navigation item.

throws luya\cms\Exception

                public function getModel()
{
    if ($this->_model === null) {
        $this->_model = Nav::findOne($this->navId);
        if (empty($this->_model)) {
            throw new Exception('The model active record could not be found for the corresponding nav item. Maybe you have inconsistent Database data.');
        }
    }
    return $this->_model;
}

            
getModuleName() public method

If the type of the item is equals 2 we can detect the module name and returns this information.

public boolean|string getModuleName ( )
return boolean|string

The name of the module or false if not found or wrong type

                public function getModuleName()
{
    if ($this->getType() === 2) {
        return $this->itemArray['module_name'];
    }
    return false;
}

            
getNavId() public method

Get the Nav-id of the Item, the Nav-Id is not unique but in case of the language container the nav id is unique. The Nav-Id identifier repersents the id coluumn of the cms_nav table.

public integer getNavId ( )

                public function getNavId()
{
    return (int) $this->itemArray['nav_id'];
}

            
getNextSibling() public method

Get the next sibling in the current siblings list.

If there is no next sibling (assuming its the last sibling item in the list) false is returned, otherwise the {{luya\cms\menu\Item}} is returned.

public luya\cms\menu\Item|boolean getNextSibling ( )
return luya\cms\menu\Item|boolean

Returns the next sibling based on the current sibling, if not found false is returned.

                public function getNextSibling()
{
    return (new Query())
        ->where(['parent_nav_id' => $this->parentNavId, 'container' => $this->container])
        ->andWhere(['>', 'sort_index', $this->sortIndex])
        ->with($this->_with)
        ->lang($this->lang)
        ->orderBy(['sort_index' => SORT_ASC])
        ->one();
}

            
getParent() public method

Returns a Item-Object of the parent element, if no parent element exists returns false.

public luya\cms\menu\Item|boolean getParent ( )
return luya\cms\menu\Item|boolean

Returns the parent item-object or false if not exists.

                public function getParent()
{
    return (new Query())
        ->where(['nav_id' => $this->parentNavId, 'container' => $this->getContainer()])
        ->with($this->_with)
        ->lang($this->lang)
        ->one();
}

            
getParentNavId() public method

Get the parent_nav_id of the current item. If the current Item-Object belongs to a parent navigation item, the getParentNavId() method returns the getNavId() of the parent item.

.
├── item (navId 1)
└── item (navId 2)
    ├── item (navId 3 with parentNavId 2)
    └── item (navId 4 with parentNavId 2)
public integer getParentNavId ( )

                public function getParentNavId()
{
    return (int) $this->itemArray['parent_nav_id'];
}

            
getParents() public method

Return all parent elements without the current item.

public luya\cms\menu\QueryIteratorFilter getParents ( )
return luya\cms\menu\QueryIteratorFilter

An array with Item-Objects.

                public function getParents()
{
    $parent = $this->with($this->_with)->getParent();
    $data = [];
    while ($parent) {
        $data[] = $parent;
        $parent = $parent->with($this->_with)->getParent();
    }
    return Query::createArrayIterator(array_reverse($data), $this->lang, array_flip($this->_with), false);
}

            
getPrevSibling() public method

Get the previous sibling in the current siblings list.

If there is no previous sibling (assuming its the first sibling item in the list) false is returned, otherwise the {{luya\cms\menu\Item}} is returned.

public luya\cms\menu\Item|boolean getPrevSibling ( )
return luya\cms\menu\Item|boolean

Returns the previous sibling based on the current sibling, if not found false is returned.

                public function getPrevSibling()
{
    return (new Query())
        ->where(['parent_nav_id' => $this->parentNavId, 'container' => $this->container])
        ->andWhere(['<', 'sort_index', $this->sortIndex])
        ->with($this->_with)
        ->lang($this->lang)
        ->orderBy(['sort_index' => SORT_DESC])
        ->one();
}

            
getProperty() public method

Get Property Object.

This method allows you the retrieve a property for an page property. If the property is not found false will be retunrend otherwhise the property object itself will be returned {{luya\admin\base\Property}} so you can retrieve the value of the property by calling your custom method or the default getValue() method.

In order to return the value, which is mostly the case, use: {{luya\cms\menu\Item::getPropertyValue}}

public luya\admin\base\Property getProperty ( $varName )
$varName string

The variable name of the property defined in the method {{luya\admin\base\Property::varName}}

                public function getProperty($varName)
{
    return $this->model->getProperty($varName);
}

            
getPropertyValue() public method

Get the value of a Property Object.

Compared to {{luya\cms\menu\Item::getProperty}} this method returns only the value for a given property. If the property is not assigned for the current Menu Item the $defaultValue will be returned, which is null by default.

public string|mixed getPropertyValue ( $varName, $defaultValue null )
$varName string

The variable name of the property defined in the method {{luya\admin\base\Property::varName}}

$defaultValue mixed

The default value which will be returned if the property is not set for the current page.

return string|mixed

Returns the value of {{luya\admin\base\Property::getValue}} if set, otherwise $defaultValue.

                public function getPropertyValue($varName, $defaultValue = null)
{
    return $this->getProperty($varName) ? $this->getProperty($varName)->getValue() : $defaultValue;
}

            
getSeoTitle() public method

Returns the Alternative SEO-Title.

If no SEO-Title is given, the page title from {{luya\cms\menu\Item::getTitle}} will be returned instead.

public string getSeoTitle ( )
return string

Return the SEO-Title, if empty the {{luya\cms\menu\Item::getTitle}} will be returned instead.

                public function getSeoTitle()
{
    return empty($this->itemArray['title_tag']) ? $this->title : $this->itemArray['title_tag'];
}

            
getSiblings() public method

Get all sibilings for the current item, this also includes the current item iteself.

public luya\cms\menu\QueryIteratorFilter getSiblings ( )
return luya\cms\menu\QueryIteratorFilter

An array with all item-object siblings

                public function getSiblings()
{
    return (new Query())
        ->where(['parent_nav_id' => $this->parentNavId, 'container' => $this->container])
        ->with($this->_with)
        ->lang($this->lang)
        ->all();
}

            
getSortIndex() public method

Get the sorting index position for the item on the current siblings.

public integer getSortIndex ( )
return integer

Sort index position for the current siblings list.

                public function getSortIndex()
{
    return (int) $this->itemArray['sort_index'];
}

            
getTarget() public method

Get the target attribute value inside the Link tag.

Can be either _blank, _self.

public string getTarget ( )
return string

Returns the target string value for the link resource.

                public function getTarget()
{
    return empty($this->_target) ? '_self' : $this->_target;
}

            
getTeardown() public method

Return all parent elements with the current item.

public luya\cms\menu\QueryIteratorFilter getTeardown ( )
return luya\cms\menu\QueryIteratorFilter

An array with Item-Objects.

                public function getTeardown()
{
    $data = [];
    $parent = $this->with($this->_with)->getParent();
    $current = $this;
    $data[$current->id] = $current;
    while ($parent) {
        $data[$parent->id] = $parent;
        $parent = $parent->with($this->_with)->getParent();
    }
    return Query::createArrayIterator(array_reverse($data, true), $this->lang, array_flip($this->_with), false);
}

            
getTitle() public method

Returns the current Title of the Menu Item.

public string getTitle ( )
return string

E.g. "Hello World"

                public function getTitle()
{
    return $this->itemArray['title'];
}

            
getType() public method

Return the current nav item type by number.

  • 1 = Page with blocks
  • 2 = Module
  • 3 = Redirect
public integer getType ( )
return integer

The type number

                public function getType()
{
    return (int) $this->itemArray['type'];
}

            
getUserCreated() public method

Returns an active record object for the admin user who created this page.

public luya\admin\models\User|boolean getUserCreated ( )
return luya\admin\models\User|boolean

Returns an ActiceRecord for the admin user who created the page, if not found the return value is false.

                public function getUserCreated()
{
    return User::findOne($this->itemArray['create_user_id']);
}

            
getUserUpdated() public method

Returns an active record object for the admin user who last time updated this page.

public luya\admin\models\User|boolean getUserUpdated ( )
return luya\admin\models\User|boolean

Returns an ActiceRecord for the admin user who last time updated this page, if not found the return value is false.

                public function getUserUpdated()
{
    return User::findOne($this->itemArray['update_user_id']);
}

            
hasMethod() public method

Defined in: yii\base\BaseObject::hasMethod()

Returns a value indicating whether a method is defined.

The default implementation is a call to php function method_exists(). You may override this method when you implemented the php magic method __call().

public boolean hasMethod ( $name )
$name string

The method name

return boolean

Whether the method is defined

                public function hasMethod($name)
{
    return method_exists($this, $name);
}

            
hasProperty() public method

Defined in: yii\base\BaseObject::hasProperty()

Returns a value indicating whether a property is defined.

A property is defined if:

  • the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also:

public boolean hasProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property is defined

                public function hasProperty($name, $checkVars = true)
{
    return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}

            
init() public method

Item-Object initiliazer, verify if the itemArray property is empty.

public void init ( )
throws luya\cms\Exception

                public function init()
{
    if ($this->itemArray === null) {
        throw new Exception('The itemArray property can not be null.');
    }
    // call parent object initializer
    parent::init();
}

            
redirectMapData() protected method

Internal used to retriev redirect data.

The redirect data commonly has the following keys:

  • type: Its a number which represents the redirect type (1 = internal, 2 = external, etc.)
  • value: A value which associated for the type (file could a file id but external link could be a string with the url)
protected void redirectMapData ( $key )
$key

                protected function redirectMapData($key)
{
    return !empty($this->itemArray['redirect']) ? $this->itemArray['redirect'][$key] : false;
}

            
resolveFields() protected method

Defined in: yii\base\ArrayableTrait::resolveFields()

Determines which fields can be returned by toArray().

This method will first extract the root fields from the given fields. Then it will check the requested root fields against those declared in fields() and extraFields() to determine which fields can be returned.

protected array resolveFields ( array $fields, array $expand )
$fields array

The fields being requested for exporting

$expand array

The additional fields being requested for exporting

return array

The list of fields to be exported. The array keys are the field names, and the array values are the corresponding object property names or PHP callables returning the field values.

                protected function resolveFields(array $fields, array $expand)
{
    $fields = $this->extractRootFields($fields);
    $expand = $this->extractRootFields($expand);
    $result = [];
    foreach ($this->fields() as $field => $definition) {
        if (is_int($field)) {
            $field = $definition;
        }
        if (empty($fields) || in_array($field, $fields, true)) {
            $result[$field] = $definition;
        }
    }
    if (empty($expand)) {
        return $result;
    }
    foreach ($this->extraFields() as $field => $definition) {
        if (is_int($field)) {
            $field = $definition;
        }
        if (in_array($field, $expand, true)) {
            $result[$field] = $definition;
        }
    }
    return $result;
}

            
setIsHidden() public method

Override the default hidden state of an item.

public void setIsHidden ( $value )
$value boolean

True or False depending on the visbility of the item.

                public function setIsHidden($value)
{
    $this->itemArray['is_hidden'] = (int) $value;
}

            
setModel() public method

Setter method for the Model.

public void setModel ( $model )
$model null|luya\cms\models\Nav

The Nav model Active Record

                public function setModel($model)
{
    $this->_model = $model;
}

            
setTarget() public method

Setter method for the link target.

public void setTarget ( $target )
$target string

                public function setTarget($target)
{
    $this->_target = $target;
}

            
setTitle() public method

Override the current title of item.

public void setTitle ( $title )
$title string

The title to override of the existing.

                public function setTitle($title)
{
    $this->itemArray['title'] = $title;
}

            
toArray() public method

Defined in: yii\base\ArrayableTrait::toArray()

Converts the model into an array.

This method will first identify which fields to be included in the resulting array by calling resolveFields(). It will then turn the model into an array with these fields. If $recursive is true, any embedded objects will also be converted into arrays. When embedded objects are yii\base\Arrayable, their respective nested fields will be extracted and passed to toArray().

If the model implements the yii\web\Linkable interface, the resulting array will also have a _link element which refers to a list of links as specified by the interface.

public array toArray ( array $fields = [], array $expand = [], $recursive true )
$fields array

The fields being requested. If empty or if it contains '*', all fields as specified by fields() will be returned. Fields can be nested, separated with dots (.). e.g.: item.field.sub-field $recursive must be true for nested fields to be extracted. If $recursive is false, only the root fields will be extracted.

$expand array

The additional fields being requested for exporting. Only fields declared in extraFields() will be considered. Expand can also be nested, separated with dots (.). e.g.: item.expand1.expand2 $recursive must be true for nested expands to be extracted. If $recursive is false, only the root expands will be extracted.

$recursive boolean

Whether to recursively return array representation of embedded objects.

return array

The array representation of the object

                public function toArray(array $fields = [], array $expand = [], $recursive = true)
{
    $data = [];
    foreach ($this->resolveFields($fields, $expand) as $field => $definition) {
        $attribute = is_string($definition) ? $this->$definition : $definition($this, $field);
        if ($recursive) {
            $nestedFields = $this->extractFieldsFor($fields, $field);
            $nestedExpand = $this->extractFieldsFor($expand, $field);
            if ($attribute instanceof Arrayable) {
                $attribute = $attribute->toArray($nestedFields, $nestedExpand);
            } elseif ($attribute instanceof \JsonSerializable) {
                $attribute = $attribute->jsonSerialize();
            } elseif (is_array($attribute)) {
                $attribute = array_map(
                    function ($item) use ($nestedFields, $nestedExpand) {
                        if ($item instanceof Arrayable) {
                            return $item->toArray($nestedFields, $nestedExpand);
                        } elseif ($item instanceof \JsonSerializable) {
                            return $item->jsonSerialize();
                        }
                        return $item;
                    },
                    $attribute
                );
            }
        }
        $data[$field] = $attribute;
    }
    if ($this instanceof Linkable) {
        $data['_links'] = Link::serialize($this->getLinks());
    }
    return $recursive ? ArrayHelper::toArray($data) : $data;
}

            
with() public method

You can use with() before the following methods:

  • {{luya\cms\menu\Item::getParent()}}
  • {{luya\cms\menu\Item::getParents()}}
  • {{luya\cms\menu\Item::getTeardown()}}
  • {{luya\cms\menu\Item::getChildren()}}
  • {{luya\cms\menu\Item::hasChildren()}}
  • {{luya\cms\menu\Item::getDescendants()}}

Example use of with in subquery of the current item:

if ($item->with(['hidden'])->hasChildren) {
    print_r($item->getChildren());
}

The above example display also hidden pages.

See also luya\cms\menu\Query::with().

public void with ( $with )
$with

                public function with($with)
{
    $this->_with = (array) $with;
    return $this;
}

            
without() public method

Unset a value from the with() method.

Assuming to return the first level with hidden items but the second level without the hidden elements:

foreach ($item->with('hidden')->children as $child) {
    // but get the sibilings without the hidden state
    $siblings = $child->without('hidden')->siblings;
}
public luya\cms\menu\Item without ( $without )
$without string|array

Can be a string hidden or an array ['hidden'].

                public function without($without)
{
    $without = (array) $without;
    foreach ($without as $expression) {
        $key = array_search($expression, $this->_with);
        if ($key !== false) {
            unset($this->_with[$key]);
        }
    }
    return $this;
}