Class luya\cms\menu\Item
Inheritance | luya\cms\menu\Item » yii\base\BaseObject |
---|---|
Implements | luya\web\LinkInterface, yii\base\Arrayable, yii\base\Configurable |
Uses Traits | luya\web\LinkTrait, yii\base\ArrayableTrait |
Available since version | 1.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
Property | Type | Description | Defined By |
---|---|---|---|
$absoluteLink | string | The link path with prepand website host https://luya.io/home/about-us . |
luya\cms\menu\Item |
$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 |
$link | string | Returns the current item link relative path with composition (language). | 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
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
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
The link path with prepand website host https://luya.io/home/about-us
.
Get all children of the current item. Children means going the depth/menulevel down e.g. from 1 to 2.
Returns an unix timestamp when the page was created.
Returns an unix timestamp when the page was last time updated.
Returns the depth of the navigation tree start with 1. Also known as menu level.
Get all childrens with childrens children.
Returns the page description (used for making meta key description).
Check whether an item has childrens or not returning a boolean value.
Check whether the parent has items or not.
Returns the href string which can be either with or without domain.
Returns Unique identifier of item, represents data record of cms_nav_item table.
The Image object or false if no image has been uploaded
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.
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.
Returns true if the item is the home item, otherwise false.
The item property containing the informations with key value parinings. This property will be assigned when creating the Item-Object.
Returns an array of user defined keywords for this page (user to generate meta keywords)
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.
Returns the current item link relative path with composition (language). The path is always relativ to the host.
Returns the {{\luya\cms\models\Nav}} object for the current navigation item.
Returns the name of the module if its of type module(2)
Returns the next sibling based on the current sibling, if not found false is returned.
Returns a Item-Object of the parent element, if no parent element exists returns false.
Return all parent elements without the current item.
Returns the previous sibling based on the current sibling, if not found false is returned.
Returns the Alternative SEO-Title. If entry is empty, the $title will returned instead.
Get all sibilings for the current item, this also includes the current item iteself.
An array with all item-object siblings
Sort index position for the current siblings list.
Returns the target string value for the link resource.
Return all parent elemtns with the current item.
Returns the type of page 1=Page with blocks, 2=Module, 3=Redirect
Returns an active record object for the admin user who created this page.
Returns an active record object for the admin user who last time updated this page.
Method Details
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()");
}
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();
}
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);
}
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.
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;
}
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);
}
}
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();
}
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.
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);
}
}
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);
}
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);
}
::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();
}
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;
}
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 [];
}
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);
}
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);
}
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 nameemail
;firstName
andlastName
: the field names arefirstName
andlastName
, and their values are obtained from thefirst_name
andlast_name
properties;fullName
: the field name isfullName
. Its value is obtained by concatenatingfirst_name
andlast_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'];
}
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 |
---|
public function getAbsoluteLink()
{
return Yii::$app->request->hostInfo . $this->getLink();
}
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'];
}
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();
}
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'];
}
Returns an unix timestamp when the page was created.
public integer getDateCreated ( ) | ||
return | integer |
Unix timestamp |
---|
public function getDateCreated()
{
return $this->itemArray['timestamp_create'];
}
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'];
}
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'];
}
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);
}
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'];
}
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;
}
Check whether the parent has items or not.
public boolean getHasParent ( ) |
public function getHasParent()
{
return (bool) $this->getParent();
}
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();
}
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'];
}
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']);
}
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;
}
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'));
}
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'];
}
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'];
}
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'];
}
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;
}
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 |
---|
public function getLink()
{
// take care of redirect
if ($this->getType() === 3 && !empty($this->redirectMapData('value'))) {
// generate convert object to determine correctn usage.
$converter = new LinkConverter([
'type' => $this->redirectMapData('type'),
'value' => $this->redirectMapData('value'),
'target' => $this->redirectMapData('target'),
]);
if ($this->redirectMapData('target')) {
$this->setTarget($this->redirectMapData('target'));
}
switch ($converter->type) {
case $converter::TYPE_EXTERNAL_URL:
return $converter->getWebsiteLink($converter->value, $converter->target)->getHref();
case $converter::TYPE_INTERNAL_PAGE:
if (empty($converter->value) || $converter->value == $this->navId) {
return;
}
$page = $converter->getPageLink($converter->value, $converter->target, $this->lang);
return $page ? $page->getHref() : '';
case $converter::TYPE_LINK_TO_EMAIL:
return $converter->getEmailLink($converter->value)->getHref();
case $converter::TYPE_LINK_TO_FILE:
return $converter->getFileLink($converter->value, $converter->target)->getHref();
case $converter::TYPE_LINK_TO_TELEPHONE:
return $converter->getTelephoneLink($converter->value)->getHref();
}
}
// if its the homepage and the default lang short code is equasl to this lang the link has no path.
if ($this->itemArray['is_home'] && Yii::$app->composition->defaultLangShortCode == $this->itemArray['lang']) {
return Yii::$app->urlManager->prependBaseUrl('');
}
return $this->itemArray['link'];
}
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;
}
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;
}
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();
}
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();
}
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);
}
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();
}
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);
}
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;
}
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'];
}
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();
}
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'];
}
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;
}
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);
}
Returns the current Title of the Menu Item.
public string getTitle ( ) | ||
return | string |
E.g. "Hello World" |
---|
public function getTitle()
{
return $this->itemArray['title'];
}
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'];
}
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']);
}
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']);
}
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);
}
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);
}
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();
}
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;
}
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;
}
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;
}
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;
}
Setter method for the link target.
public void setTarget ( $target ) | ||
$target | string |
public function setTarget($target)
{
$this->_target = $target;
}
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;
}
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
|
$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 | 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;
}
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;
}
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 |
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;
}