Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed navItem relation for inactive page versions #415

Merged
merged 5 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading