public function testFindContent() { $nav = Nav::findOne(1); /* @var $item \luya\cms\models\NavItem */ $item = $nav->activeLanguageItem; $this->assertSame('Homepage', $item->title); $this->assertSame('homepage', $item->alias); }
/** * Get the content of Nav for the current active language with cmslayout or placeholder. * * @param string $value The value of the Nav ID e.g 1 (hover the cms menu to see the ID). * @param string|null $sub If null this parameter will be ignored otherwise its the name of the placeholder inside this cmslayout. * @return string The content rendered with the cmslayout, or if $sub is provided and not null with its placeholder name. * @see \luya\tag\TagInterface::parse() */ public function parse($value, $sub) { $page = Nav::findOne($value); // verify if the page is of type content if ($page) { if ($page->activeLanguageItem->nav_item_type !== NavItem::TYPE_PAGE) { return null; } if (empty($sub)) { return $page->activeLanguageItem->getContent(); } else { return $page->activeLanguageItem->type->renderPlaceholder($sub); } } return null; }
public function getRowDescriber() { if (!empty($this->row_id)) { switch ($this->table_name) { case "nav": return Nav::findOne($this->row_id)->activeLanguageItem->title; case "nav_item": return NavItem::findOne($this->row_id)->title; case "cms_nav_item_page_block_item": $block = NavItemPageBlockItem::findOne($this->row_id); if (!$block || $block->block == null) { $arr = $this->getMessageArray(); if (!empty($arr) && isset($arr['blockName'])) { return $arr['blockName'] . " ({$arr['pageTitle']})"; } else { return; } } return $block->block->getNameForLog() . " (" . $block->droppedPageTitle . ")"; } } }
/** * 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 (implements `\admin\base\Property`) so you can retrieve the value of the * property by calling your custom method or the default `getValue()` method. * * @param string $varName The variable name of the property defined inside of the property of the method `varName()`. * @since 1.0.0-beta8 */ public function getProperty($varName) { 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->getProperty($varName); }
public function actionCreateRedirect() { Yii::$app->menu->flushCache(); $model = new Nav(); $parentNavId = $this->postArg('parent_nav_id'); $navContainerId = $this->postArg('nav_container_id'); if (!empty($parentNavId)) { $navContainerId = Nav::findOne($parentNavId)->nav_container_id; } $create = $model->createRedirect($parentNavId, $navContainerId, $this->postArg('lang_id'), $this->postArg('title'), $this->postArg('alias'), $this->postArg('redirect_type'), $this->postArg('redirect_type_value'), $this->postArg('description')); if ($create !== true) { Yii::$app->response->statusCode = 422; } return $create; }
/** * Get Container name for a nav item. * * @param $navId * @return string Container name */ public function actionGetNavContainerName($navId) { $nav = Nav::findOne($navId); if ($nav) { $navCoontainer = NavContainer::findOne($nav->nav_container_id); if ($navCoontainer) { return $navCoontainer->name; } } return ""; }