TYPO3,新闻:通过获取参数更改排序顺序和方向

TYPO3, news: change sort order and direction via get parameter

在扩展新闻的列表视图中,我们需要更改排序顺序和排序方向的链接。是否有可能通过获取参数更改两者? 我取消选中选项 "Disable override demand" 并尝试了一些组合,例如

?tx_news_pi1[orderDirection]=asc
?tx_news_pi1[settings][orderDirection]=asc

但这不起作用。

谢谢!

也许试试:

tx_news_pi1[overwriteDemand][orderDirection]=asc

(虽然我不确定 orderDirection 是否正确,但可以检查 manual/code)

据我所知,没有直观的选项可以在流体模板中包含排序,因为所有排序都是在 TypoScript 和 FlexForm 级别上完成的。

不过,有不同的选项可以从前端启用排序:

  1. 在TypoScript中,你根据当前的URL参数设置排序参数,最简单的方法是按条件解决,你也可以自由定义自己的不拘参数的消息-API.
    用于排序的 URLs 在任何情况下都应该使用 viewHelper 创建,始终附加 cHash 并计算正确。

    TypoScript:

    #######
    ## Here you transfer the URL-parameters for sorting to the TypoScript-settings
    ## and also assure that only predefined values are accepted
    #######
    [globalVar = _GET|tx_news_pi1|orderBy = title]
        plugin.tx_news.settings.orderBy = title
    [globalVar = _GET|tx_news_pi1|orderBy = datetime]
        plugin.tx_news.settings.orderBy = datetime
    [globalVar = _GET|tx_news_pi1|orderBy = tstamp]
        plugin.tx_news.settings.orderBy = tstamp
    [globalVar = _GET|tx_news_pi1|orderBy = crdate]
        plugin.tx_news.settings.orderBy = crdate
    [global]
    
    [globalVar = _GET|tx_news_pi1|sort = desc]
        plugin.tx_news.settings.orderDirection = desc
    [else]
        plugin.tx_news.settings.orderDirection = asc
    [global]
    

    Fluid:

    <f:link.action action="list" addQueryString="&tx_news_pi1[orderBy]=title&tx_news_pi1[sort]=asc">Sort by title: asc</f:link.action>
    <f:link.action action="list" addQueryString="&tx_news_pi1[orderBy]=title&tx_news_pi1[sort]=desc">Sort by title: desc</f:link.action>
    

    This solution is not tested and it might be required still to adjust some things but in general it should be working.
    Cache-related issues are considered the same as with news-records in general, at least related to any required settings.
    Sorting by further fields requires further steps as stated here: https://docs.typo3.org/typo3cms/extensions/news/DeveloperManual/ExtendNews/ExtendFlexforms/Index.html#selectbox-sort-by

  2. 其他单独的解决方案需要在 PHP 中编程并且可以基于 hook 和信号,新闻手册包括几个可能有用的章节:

  3. 此外,可能存在解决排序作业的扩展,但我不知道。您可以搜索 news-related extensions. I could imagine that eventnews or dataviewer 可能会有用,但我从未检查过,这些扩展可能根本没有用。
    您也有可能在进一步搜索时发现另一个有用的扩展。如果是这样,请告诉我们 ;-)

  4. 然后仍然可以选择以某种方式以不同的方式解决所需的行为,也许它没有记录或记录不当,或者我错过了。

请注意,如果您使用分页,尤其是 AJAX based pagination

,您可能仍需要进行一些调整

我找到了问题的原因和解决方法。

原因是 flexform 中的默认排序:按标题排序。 GET-Parameter orderBy 无法覆盖 flexform 中的默认排序。如果您在 flexform 中选择默认排序,则会忽略 orderBy 参数,但 orderDirection 参数会按预期工作。结果令人困惑但一致:内容始终按默认排序排序,但排序顺序不同。

删除 flexform 中的默认排序后,一切正常。

我认为这是一种错误;我会 post 在新闻的错误跟踪器中提问。

tx_news_pi1[overwriteDemand][order]=title desc 适合我