luyadev / luya-module-cms

The LUYA CMS module provides a full functional CMS for adding contents based on blocks.
https://luya.io
MIT License
33 stars 46 forks source link

Same alias at root level in different websites is not possible #413

Open hbugdoll opened 8 months ago

hbugdoll commented 8 months ago

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().

nadar commented 8 months ago

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

hbugdoll commented 8 months ago

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

$websiteId must be provided in verifyAlias()

nadar commented 8 months ago

it must be done using:

Using a Query NavItem →Nav →NavContainer → Website

hbugdoll commented 8 months ago

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.