FluidTYPO3 / vhs

TYPO3 extension VHS: Fluid ViewHelpers
https://fluidtypo3.org
Other
189 stars 228 forks source link

Menu viewhelper shows translated pages having nav_hide=1 #1708

Closed christophlehmann closed 1 year ago

christophlehmann commented 3 years ago

How to reproduce

Misbehaviour: The menu contains the translated page.

The opposite case is also wrong (or lets say currently not supported), eg. when the page in default language has nav_hide=1 and its translation has nav_hide=0 then the translation is not in the menu.

Using different values for nav_hide by page and language is still valid

Bildschirmfoto 2021-03-02 um 15 21 57
networkteam-lange commented 3 years ago

+1

update-switzerland commented 3 years ago

I'm having the same problem with the overall v:menu viewhandler. Turns out, if a page isn't translated or hidden, the resulting link's href-attribute was just empty. I ended up editing vhs/Classes/ViewHelpers/Menu/AbstractMenuViewHelper.php directly (I know, bad).

I changed renderItemLink on line 353 to the following:

protected function renderItemLink(array $page)
    {
        $isSpacer = ($page['doktype'] === PageRepository::DOKTYPE_SPACER);
        $isCurrent = (boolean) $page['current'];
        $isActive = (boolean) $page['active'];
        $linkCurrent = (boolean) $this->arguments['linkCurrent'];
        $linkActive = (boolean) $this->arguments['linkActive'];
        $includeAnchorTitle = (boolean) $this->arguments['includeAnchorTitle'];
        $target = (!empty($page['target'])) ? ' target="' . $page['target'] . '"' : '';
        $class = (trim($page['class']) !== '') ? ' class="' . trim($page['class']) . '"' : '';

        /****
         * hack!!!
         * if the link is empty, the page is either hidden or not translated.
         * Do NOT show it in the menu
         */

        if ($page['link'] == '') {
            return '';
        }

        if ($isSpacer || ($isCurrent && !$linkCurrent) || ($isActive && !$linkActive)) {
            $html = htmlspecialchars($page['linktext']);
        } elseif ($includeAnchorTitle) {
            $html = sprintf(
                '<a href="%s" title="%s"%s%s>%s</a>',
                $page['link'],
                htmlspecialchars($page['title']),
                $class,
                $target,
                htmlspecialchars($page['linktext'])
            );
        } else {
            $html = sprintf(
                '<a href="%s"%s%s>%s</a>',
                $page['link'],
                $class,
                $target,
                htmlspecialchars($page['linktext'])
            );
        }

        return $html;
    }

Hope this has no side-effects…