TypoScript Menu: USERDEF1 and USERDEF2 states not working for tx_news

631 views Asked by At

This is "my" ages old language switch that also accounts for tx_news and does not link the language if there is no translation for a page or a news item (that's the function of USERDEF):

temp.lang_nav = HMENU
temp.lang_nav {
  special = language
  special.value = 0,1
  special.normalWhenNoLanguage = 0
  wrap = |
  1 = TMENU
  1 {
    NO = 1
    NO {
      linkWrap = <li>|</li>
      stdWrap.override = DE || EN
      # Build Typolink ourself
      doNotLinkIt = 1
      stdWrap.typolink.parameter.data = page:uid
      stdWrap.typolink.additionalParams = &L=0 || &L=1
      stdWrap.typolink.addQueryString = 1
      stdWrap.typolink.addQueryString.exclude = L,id,cHash,no_cache
      stdWrap.typolink.addQueryString.method = GET
      stdWrap.typolink.useCacheHash = 1
      stdWrap.typolink.no_cache = 0
    }

    // Active language
    ACT = 1
    ACT < .NO
    ACT {
       stdWrap.typolink.ATagParams = class="active"
    }

    // = NO + No translation
    USERDEF1 = 1
    USERDEF1 < .NO
    USERDEF1{
      //doNotShowLink = 1
      stdWrap.typolink >
    }
    // = ACT + No translation
    USERDEF2 = 1
    USERDEF2 < .USERDEF1

  }
}

Also, I've used a variant according to https://gist.github.com/michelalbers/fb0c2e04af1d6ff94788 that has a more modern syntax.

A user reported that suddenly the USERDEF state doesn't kick in anymore for untranslated news.

Actually, I can't prove this did work for untranslated news before, but I'm quite sure.

What do you think; a bug? Wrong syntax? USERDEF not for news, just for pages? Or could this have never worked at all?

If the last, is there a way to achieve such an effect (don't link to translation for untranslated news)?

1

There are 1 answers

0
Urs On

Apparently, what I'm asking for is not a feature.

A workaround to prevent users from landing on the global 404 page when using the lang switch on an untranslated item would be to make a separate 404 page for news with a clearer explanation.

If you have set something like

'pageNotFound_handling' => 'USER_FUNCTION:typo3conf/ext/template/Classes/Various/noAccess.php:noAccess->pageNotFound',

in localconf, you can do that work there.