Related page is null in translated menu items (following guide)
I followed this: https://twillcms.com/guides/page-builder-with-blade/adding-navigation.html
- I have menu component with translatable title and non translatable related page field.
- In my primary locale:
$link->getRelated('page')
works so I can do ->first()->slug()
with no problems.
- In my secondary locale I get the items with translated titles but $link->getRelated('page')
is null
.19 Replies
getRelated does not depend on the locale at all so that's a bit strange
Yes and I see same related page in admin panel when switching to translation, so I am expecting to get same related page no matter of locale setting. But on different locale related page is
null
.
I found the source of problem. I checked "active" languages in Menu but while having translations of my pages published, language checkbox was not set. So menu was rendering fine but translated pages were not "accesible" even though they were published. It's a bit confusing to have to set two attributes on a page to make it visible in frontend.It allows you to have draft translations alongside published translations and avoids all the locale content duplication issues in a lot of other CMS. but I hear it may be confusing at first
This approach seems to be reasonable, but it would be a good idea to have bulk action to enable a language for many pages, because even though I had translations and they were published I had to go again one by one to tick language checkbox on every page.
that's a good point
Also there is no locale switcher on module list or some kind of global switcher like on page edit (top right just before 'editor' button) that would allow quickly to see translated content. Maybe it would be a good idea to have just one switcher for all content in top menu bar next to user menu?
that could be nice, yes
I have another problem with menu – this time with ordering. Order is ok in admin panel (saved properly by artisan queue:work), but not when rendering… I use:
Add defaultOrder() to that query
GitHub
GitHub - lazychaser/laravel-nestedset: Effective tree structures in...
Effective tree structures in Laravel 4-8. Contribute to lazychaser/laravel-nestedset development by creating an account on GitHub.
MainMenuLink::published()->defaultOrder()->get()->toTree();
gives positions order: 3, 0, 2, 5, 1.MainMenuLink::published()->defaultOrder()->get()->toTree();
gives: 0 , 3, 4, 2, 5, 1,
MainMenuLink::published()->get()->defaultOrder()->toTree();
throws erroris your tree broken?
check consistency
In admin panel everything seems to be ok. Also rendered menu on frontpage is working fine, but just the order is wrong.
did you try
orderBy('position')
?This works fine. I thought that this is the default for sortables. 🤔