luya-module-cms icon indicating copy to clipboard operation
luya-module-cms copied to clipboard

Same alias at root level in different websites is not possible

Open hbugdoll opened this issue 1 year ago • 4 comments

After https://github.com/luyadev/luya-module-cms/pull/411 we have the following situation now:

Same alias is prevented

  1. with same parent item
  2. 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().

hbugdoll avatar Feb 26 '24 18:02 hbugdoll

agree :+1: would you like to send a PR?

nadar avatar Feb 29 '24 07:02 nadar

I would like to, but it's not clear to me yet how...

$websiteId must be provided in verifyAlias()

  • Passing $websiteId as new argument in NavItem::verifyAlias($alias, $langId, $websiteId) ...ok
  • But how obtaining $websiteId inside NavItem::validateAlias()?
    • Via Yii::$app->website->current['id'] ? Is this corresponding to currentWebsiteToggler or to the website with is_default = 1 ?
    • Using a Query NavItemNavNavContainerWebsite ?

hbugdoll avatar Feb 29 '24 09:02 hbugdoll

it must be done using:

Using a Query NavItem →Nav →NavContainer → Website

nadar avatar Feb 29 '24 11:02 nadar

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.

hbugdoll avatar Feb 29 '24 13:02 hbugdoll