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.
Twill
19 Replies
ifox
ifox3mo ago
getRelated does not depend on the locale at all so that's a bit strange
Adam Mateusz Brożyński
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.
ifox
ifox3mo ago
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
Adam Mateusz Brożyński
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.
ifox
ifox3mo ago
that's a good point
Adam Mateusz Brożyński
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?
ifox
ifox3mo ago
that could be nice, yes
Adam Mateusz Brożyński
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:
$links = MainMenuLink::published()->get()->toTree();
return view('components.main-menu', ['links' => $links]);
$links = MainMenuLink::published()->get()->toTree();
return view('components.main-menu', ['links' => $links]);
ifox
ifox3mo ago
Add defaultOrder() to that query
ifox
ifox3mo ago
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.
Adam Mateusz Brożyński
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 error
ifox
ifox3mo ago
is your tree broken? check consistency
Adam Mateusz Brożyński
In admin panel everything seems to be ok. Also rendered menu on frontpage is working fine, but just the order is wrong.
ifox
ifox3mo ago
did you try orderBy('position')?
Adam Mateusz Brożyński
This works fine. I thought that this is the default for sortables. 🤔
Want results from more Discord servers?
Add your server