Skip to content

Commit

Permalink
Merge pull request #415 from hbugdoll/fix-navitem-relation
Browse files Browse the repository at this point in the history
Fixed navItem relation for inactive page versions
  • Loading branch information
nadar authored Mar 8, 2024
2 parents 496cebc + c981e19 commit 75a2afe
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE

## 5.1.1

+ [#415](https://github.com/luyadev/luya-module-cms/pull/415) Fixed navItem relation for inactive page versions.
+ [#412](https://github.com/luyadev/luya-module-cms/pull/412) Fixed website relation for nav container (when accessing `navContainer->website`).
+ [#410](https://github.com/luyadev/luya-module-cms/pull/410) Disabled sorting functionality for the "group" extra field in the block CRUD interface due to an exception being thrown. This issue occurred because the field is declared as an `extraAttribute`.
+ [#409](https://github.com/luyadev/luya-module-cms/issues/409) Implemented a new validation check to prevent slug duplication within the same language and navigation hierarchy when creating a new page. This enhancement ensures unique page identification and avoids conflicts in site structure.
Expand Down
8 changes: 8 additions & 0 deletions src/models/NavItemPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,14 @@ public static function copyBlocks($fromPageId, $toPageId)
return true;
}

/**
* {@inheritdoc}
*/
public function getNavItem()
{
return $this->hasOne(NavItem::class, ['id' => 'nav_item_id'])->where(['nav_item_type' => static::getNummericType()]);
}

/**
* This method is used to force the parent nav item for the corresponding page item whether the type matches or not:
*
Expand Down
41 changes: 41 additions & 0 deletions tests/src/models/NavItemPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace NavItemPageTest;

use cmstests\WebModelTestCase;
use luya\cms\models\NavItem;
use luya\cms\models\NavItemPage;
use luya\testsuite\fixtures\NgRestModelFixture;
use luya\testsuite\traits\CmsDatabaseTableTrait;
Expand Down Expand Up @@ -107,4 +108,44 @@ public function testRelativeViewPath()
$this->assertStringContainsString('views/cmslayouts'.DIRECTORY_SEPARATOR.'relative.php', $e->getMessage());
}
}

public function testNavItemForPageVersions()
{
$navItemFixture = $this->createCmsNavItemFixture([
1 => [
'id' => 1,
'nav_id' => 11,
'alias' => 'foobar',
'nav_item_type' => 1,
'nav_item_type_id' => 2,
]
]);

$pageFixture = $this->createCmsNavItemPageFixture([
'version1' => [
'id' => 1,
'nav_item_id' => 1,
'version_alias' => 'first',
],
'version2' => [
'id' => 2,
'nav_item_id' => 1,
'version_alias' => 'second',
]
]);

$navItem = $navItemFixture->getModel(1);
$pageVersion1 = $pageFixture->getModel('version1'); // inactive page version
$pageVersion2 = $pageFixture->getModel('version2'); // active page version

$this->assertInstanceOf(NavItem::class, $pageVersion1->navItem);
$this->assertSame(1, $pageVersion1->navItem->id);
$this->assertSame(11, $pageVersion1->navItem->nav_id);
$this->assertSame('foobar', $pageVersion1->navItem->alias);

$this->assertInstanceOf(NavItem::class, $pageVersion2->navItem);
$this->assertSame(1, $pageVersion2->navItem->id);
$this->assertSame(11, $pageVersion2->navItem->nav_id);
$this->assertSame('foobar', $pageVersion2->navItem->alias);
}
}

0 comments on commit 75a2afe

Please sign in to comment.