Skip to content

Commit

Permalink
CMS Menu item has method getAbsoluteLink() in order to retrieve link
Browse files Browse the repository at this point in the history
with prepand host scheme. closes #1171
  • Loading branch information
nadar committed Jan 19, 2017
1 parent 974eb2c commit 49f5bea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The changelog contains informations about bug fixes, new features or bc breaking

### Added

- [#1171](https://github.com/luyadev/luya/issues/1171) CMS Menu item has method `getAbsoluteLink()` in order to retrieve link with prepand host scheme.
- [#1169](https://github.com/luyadev/luya/issues/1169) Callable function for labelFields in the CheckboxRelation Plugin.
- [#1118](https://github.com/luyadev/luya/issues/1118) Variation/Flavors for blocks can be configure in the config file in order to override and hide fields.
- [#1117](https://github.com/luyadev/luya/issues/1117) Content Proxy allows you to sync files and data from one environment into another.
Expand Down
21 changes: 18 additions & 3 deletions modules/cms/src/menu/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace luya\cms\menu;

use Yii;
use luya\cms\Exception;
use yii\base\Object;
use luya\admin\models\User;
use luya\cms\Exception;
use luya\cms\models\Nav;
use yii\base\Object;
use luya\web\LinkInterface;
use luya\web\LinkTrait;
use luya\helpers\Url;

/**
* Menu item Object.
Expand Down Expand Up @@ -43,6 +44,7 @@
* @property array $teardown Return all parent elemtns **with** the current item.
* @property array $children Get all children of the current item. Children means going the depth/menulevel down e.g. from 1 to 2.
* @property boolean $isHome Returns true if the item is the home item, otherwise false.
* @property string $absoluteLink The link path with prepand website host `http://luya.io/home/about-us`.
* @author Basil Suter <basil@nadar.io>
* @since 1.0.0-beta1
*/
Expand Down Expand Up @@ -335,7 +337,7 @@ protected function redirectMapData($key)
* from a page to a hidden page, the link of the hidden page will be returned and the link
* will be successfully displayed
*
* @return string e.g. "/home/about-us" or with composition "/de/home/about-us"
* @return string The link path `/home/about-us` or with composition `/de/home/about-us`
*/
public function getLink()
{
Expand All @@ -359,6 +361,19 @@ public function getLink()

return $this->itemArray['link'];
}

/**
* Returns the link with an absolute scheme.
*
* The link with an absolute scheme path example `http://luya.io/link` where link is the output
* from the {{luya\cms\menu\item::getLink}} method.
*
* @return string The link path with prepand website host `http://luya.io/home/about-us`.
*/
public function getAbsoluteLink()
{
return Url::base(true) . $this->getLink();
}

/**
* Returns a boolean value whether the current item is an active link or not, this
Expand Down
47 changes: 4 additions & 43 deletions modules/cms/tests/src/menu/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,51 +43,12 @@ public function testChildItem()
$this->assertFalse($obj->isHome);
}

/*
public function testFindHidden()
{
$this->assertFalse(Yii::$app->menu->findOne(['id' => 9999]));
}
public function testFindOffline()
{
$this->assertFalse(Yii::$app->menu->findOne(['id' => 7]));
}
public function testFindHiddenAndOffline()
{
$this->assertFalse(Yii::$app->menu->findOne(['id' => 9]));
}
public function testFindHiddenWithHidden()
{
$this->assertInstanceOf("luya\cms\menu\Item", Yii::$app->menu->find()->where(['id' => 8])->with('hidden')->one());
}
public function testFindOfflineWithHidden()
public function testAbsoluteLink()
{
$this->assertFalse(Yii::$app->menu->find()->where(['id' => 7])->with('hidden')->one());
}
public function testFindHiddenAndOfflineWithHidden()
{
$this->assertFalse(Yii::$app->menu->find()->where(['id' => 9])->with('hidden')->one());
}
public function testRedirectInternal()
{
$obj = Yii::$app->menu->findOne(['id' => 5]);
$this->assertEquals('/luya/envs/dev/public_html/en/page4', $obj->link);
}
public function testRedirectExternal()
{
$obj = Yii::$app->menu->findOne(['id' => 6]);
$this->assertEquals('https://luya.io', $obj->link);
$menu = (new Query())->where(['id' => 2])->one();

$this->assertSame('http://localhost/luya/envs/dev/public_html/luya/envs/dev/public_html/en/page1', $menu->absoluteLink);
}
*/
// translation tests

public function testHomeLanguageCompare()
Expand Down

0 comments on commit 49f5bea

Please sign in to comment.