TYPO3 路由和方面 - 从 URL 中删除 cHash

TYPO3 routing and aspect - remove cHash from URL

对于 TYPO3 9.5,我尝试使用自定义方面来管理我的扩展程序中的 URL。 url 代有效,但附加了一个 cHash。首先,我不想要这个 cHash(这里没有必要),其次,cHash 破坏了 link 的功能(我得到一个 cHash-comparsion-error)。

我又读了 https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.5/Feature-86365-RoutingEnhancersAndAspects.html#impact 一篇关于动态参数和 cHash 的文章。要删除 cHash,我应该为所有占位符添加方面。我只有一个占位符和一个方面,但存在 cHash。

raw-url 看起来像这样: &tx_psoabilling_pi1[action]=showband&tx_psoabilling_pi1[controller]=Band&tx_psoabilling_pi1[band]=564&cHash=jkg24hwek8ufhqwezweklfzh

它被渲染成这样: 2019-thisisaname?cHash=o28z3hkwejghweuhzlk

这里是config.yaml的部分:

 PsoabillingPlugin:
    type: Extbase
    extension: Psoabilling
    plugin: Pi1
    routes:
      - routePath: '/{yearandbandname}'
        _controller: 'Band::showband'
        _arguments: 
          yearandbandname: band
    defaultController: 'Band::listyear'
    aspects:
      yearandbandname:
        type: BandAndYearMapper

BandAndYearMapper.php

<?php

namespace EnzephaloN\ThemePsoa\Routing\Aspect;

use TYPO3\CMS\Core\Routing\Aspect\PersistedMappableAspectInterface;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;

class BandAndYearMapper implements PersistedMappableAspectInterface{

    use SiteLanguageAwareTrait;

    /**
     * @param string $value
     * @return string|null
     */
    public function generate(string $value): ?string{
        if($uid=intval($value)){
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_psoabilling_domain_model_band');
            $statement = $queryBuilder
               ->select('b.uid', 'b.name', 'y.year')
               ->from('tx_psoabilling_domain_model_band','b')
               ->leftJoin('b', 'tx_psoabilling_domain_model_year', 'y', 'b.year = y.uid')
               ->where(
                  $queryBuilder->expr()->eq('b.uid', $queryBuilder->createNamedParameter($uid))
               )
               ->execute();
            if($record = $statement->fetch()){
                if(is_array($record)){
                    return $record['year']. "-" .str_replace(" ","-",trim(strtolower($record['name'])));
                }
            }
        }
        return null;
    }

    /**
     * @param string $value
     * @return string|null
     */
    public function resolve(string $value): ?string{
        $year = substr($value, 0, 4);
        $name = str_replace("-", " ", substr($value, 5));
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_psoabilling_domain_model_band');
        $statement = $queryBuilder
            ->select('b.uid')
            ->from('tx_psoabilling_domain_model_band','b')
            ->leftJoin('b', 'tx_psoabilling_domain_model_year', 'y', 'b.year = y.uid')
            ->where(
                $queryBuilder->expr()->andX(
                    $queryBuilder->expr()->eq('y.year', $queryBuilder->createNamedParameter($year)),
                    $queryBuilder->expr()->orX(
                        $queryBuilder->expr()->like('b.name', $queryBuilder->createNamedParameter($name)),
                        $queryBuilder->expr()->like('b.name', $queryBuilder->createNamedParameter(substr($value, 5))), // if there was a - inside the bandname
                        $queryBuilder->expr()->like('b.name', $queryBuilder->createNamedParameter(substr($value, 5, strpos($name, " ")-1).'%')) // just find by beginning
                    )
                )
            )
            ->execute();
        if($record = $statement->fetch()){
            return (string)$record['uid'];
        }
        return null;
    }
}

如何删除cHash?

如 Susi 所写,切换到 StaticMappableAspectInterface 是解决方案。 class 现在开始于:

<?php

namespace EnzephaloN\ThemePsoa\Routing\Aspect;

use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;

class BandAndYearMapper implements StaticMappableAspectInterface{