luya-module-cms
luya-module-cms copied to clipboard
Same alias at root level in different websites is not possible
After https://github.com/luyadev/luya-module-cms/pull/411 we have the following situation now:
Same alias is prevented
- with same parent item
- or at root level ("same"
parent_nav_id
=0
).
/* this is possible */ /* this is NOT possible */
Website1 Website1
├── alias_a ├── alias_a
│ ├── alias_b │ ├── alias_c
│ └── alias_c │ └── alias_c ↯
├── alias_b ├── alias_b
│ └── alias_c │ └── alias_c
└── alias_c └── alias_a ↯
That is the desired behavior.
But there is no support of multiple websites in verifyAlias()
.
The GROUP BY clause https://github.com/luyadev/luya-module-cms/blob/f77915060d7531f14d38af61fc0b4825cd06e805/src/models/NavItem.php#L270 doesn't reach it. In my opinion this clause can be omitted because of the presence of ->exists()
.
Currently, it's not possible to have two pages at root level with same alias but in different websites,
because of "same" parent_nav_id
= 0
.
/* this is currently NOT possible */
Website1
├── homepage
├── alias_a
│ └── alias_c
└── alias_b
Website2
├── homepage ↯
├── alias_c
│ └── alias_d
└── alias_b ↯
The WHERE clause https://github.com/luyadev/luya-module-cms/blob/f77915060d7531f14d38af61fc0b4825cd06e805/src/models/NavItem.php#L269 should be something like
->where(['cms_nav_item.alias' => $alias, 'cms_nav_item.lang_id' => $langId, 'cms_nav.parent_nav_id' => $parentNavId, 'cms_nav_container.website_id' => $websiteId])
and $websiteId
must be provided in verifyAlias()
.
agree :+1: would you like to send a PR?
I would like to, but it's not clear to me yet how...
$websiteId must be provided in verifyAlias()
- Passing
$websiteId
as new argument inNavItem::verifyAlias($alias, $langId, $websiteId)
...ok - But how obtaining
$websiteId
insideNavItem::validateAlias()
?- Via
Yii::$app->website->current['id']
? Is this corresponding tocurrentWebsiteToggler
or to the website withis_default = 1
? - Using a Query
NavItem
→Nav
→NavContainer
→Website
?
- Via
it must be done using:
Using a Query NavItem →Nav →NavContainer → Website
it must be done using:
Using a Query NavItem →Nav →NavContainer → Website
Is not possible, because nav_id
is not yet set for the Nav Item when validateAlias()
is called during page creating.