Jump to content

getLanguages() method does not return data if page template does not have template file / possibly bug?


Zeka
 Share

Recommended Posts

Hi PWers.

Im builing some kind of menu system for my current multilanguage project. 

$menu - is main menus page

$menu->menu_groups - is PageTable field that hold menus groups

$menu->menu_groups->menu_items - is repeater field that hold menu items

Here is the code of it:

<div class="sidebar-right">
    <nav class="sidebar-nav">
        <ul class="sidebar-nav__groups">
            <?php
                $currentLang = $user->language;
                $currentPageId = $page->id;

                foreach ($menus->menu_groups as $menu_group) {
                    $groupLanguages = $menu_group->getLanguages();
                    bd($groupLanguages);
                    if ($menu_group->menu_group_position == 2 ) {
                        echo "<li class='sidebar-nav__group-title'>". $menu_group->title ."</li>";
                        echo "<ul class='sidebar-nav__list'>";
                        foreach ($menu_group->menu_items as $menu_item) {
                            $out = "";
                            // If user enter custom link
                            if ($menu_item->menu_item_custom_link) {
                                $out .= "<li class='sidebar-nav__list-item'>";
                                $out .= "<a class='sidebar-nav__list-item-link' target='_blank' href='". $menu_item->menu_item_custom_link ."'>";
                                $out .= $menu_item->menu_item_title;
                                $out .= "</a>";
                                $out .= "</li>";
                            } else {
                                // Get list of active languages for this page
                                if ($menu_item->menu_item_page) {
                                    $pageLanguages = $menu_item->menu_item_page->getLanguages();
                                    bd($pageLanguages);
                                    $children = $menu_item->menu_item_page->children();
                                    $isChild = $children->has($page);
                                    $active_item = ($currentPageId == $menu_item->menu_item_page->id || $isChild ? "sidebar-nav__list-item--active" : "");
                                    $active_link = ($currentPageId == $menu_item->menu_item_page->id || $isChild ? "sidebar-nav__list-item-link--active" : "");
                                    // Menu item markup if current language is active for current page
                                    if ($pageLanguages->has($currentLang)) {
                                        $out .= "<li class='sidebar-nav__list-item ". $active_item ."'>";
                                        $out .= "<a class='sidebar-nav__list-item-link ". $active_link ."' href='". $menu_item->menu_item_page->url ."'>";
                                        $out .= $menu_item->menu_item_title;
                                        $out .= "</a>";
                                        $out .= "</li>";
                                    }
                                }
                            }
                            echo $out;
                        }
                        echo "</ul>";
                    }
                }
            ?>
        </ul>
    </nav>
</div>

Im using Tracy Debuger module, so i will show outputs of it.

When i get languages of a page of menu item, getLanguages returns expected data 

$pageLanguages = $menu_item->menu_item_page->getLanguages();
bd($pageLanguages);

Screenshot_4.jpg

But when i try to get languages of a pages of menu groups getLanguages() returns:

$groupLanguages = $menu_group->getLanguages();
bd($groupLanguages);

Screenshot_3.jpg

Also i had tried to get languages by this code: 

$groupId = $menu_group->id;
bd($pages->get($groupId)->getLanguages());

But got the same result.

All languages are active on all pages.

PW 3.0.25

Am i doing something wrong or missing something? 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...