bednee / cooluri

GIT repository for TYPO3 extension CoolUri
7 stars 12 forks source link

Missing query arguments in language menus #62

Open mbrodala opened 7 years ago

mbrodala commented 7 years ago

When generating e.g. language menus with addQueryString, current internal query string arguments are not taken into account.

This can easily be reproduced by opening e.g. a news record and having a look at the URI pointing to translations of that news record: the URI will point to the detail page instead of the specific record.

We currently use the following to map the news parameter within an URI:

<part>
  <parameter>tx_news_pi1[news]</parameter>
  <lookindb>
    <to>SELECT title FROM tx_news_domain_model_news WHERE (uid=$1 or l10n_parent=$1) AND sys_language_uid={L=0}</to>
    <t3conv>1</t3conv>
  </lookindb>
</part>

After some debugging we found out that it's related to $_SERVER['QUERY_STRING']:

When processing a request, CoolURI first retrieves this value through GeneralUtility::getIndpEnv('QUERY_STRING'), and processes it. At this point $_SERVER['QUERY_STRING'] is still empty and only updated afterwards.

However, there is a runtime cache for GeneralUtility::getIndpEnv() since TYPO3 7.5, thus every subsequent call to GeneralUtility::getIndpEnv('QUERY_STRING') will return the original empty value.

And this brings us back to the menus: if you set addQueryString = 1, AbstractMenuContentObject::prepareMenuItemsForLanguageMenu() calls the ContentObjectRenderer::getQueryArguments() method which uses GeneralUtility::getIndpEnv('QUERY_STRING') if no method was specified (default) and thus gets the initial empty value.

To finalize everything: CoolURI should directly access $_SERVER['QUERY_STRING] and thus bypass the runtime cache of GeneralUtility::getIndpEnv(). There is a method GeneralUtility::flushInternalRuntimeCaches() but it's marked as @internal and should thus not be used here.

Our temporary workaround to fix the language menus is adding addQueryStringMethod = GET which then uses the uncached raw GET parameters.

pitchart commented 7 years ago

Hi, I face the same problem on different cases.

In fact it's the addQueryString option for typolink is broken using cooluri since the introduction of GeneralUtility runtime cache. Unfortunatly the addQueryStringMethod parameter is not always available to use (ex: f:form viewhelper).

I tried @mbrodala's solution and used directly $_SERVER['QUERY_STRING'] in the CoolUri->decodeSpURL_createQueryStringParam() and all broken cases are fixed.

Are you ok for a PR ?