TYPO3:将 fe_users realurl 配置迁移到 routeEnhancers

TYPO3: Migrating fe_users realurl configuration to routeEnhancers

TYPO3:将 fe_users realurl 配置迁移到 routeEnhancers

目前我正在将 TYPO3 从版本 8 更新到版本 9。到目前为止,我已经使用 ext:realurl 生成语音 url。现在我正在努力让 "old" url 与新的 routeEnhancers 一起工作。

我在自己的扩展中使用字段 my_department 扩展了 fe_users table。现在,我正在尝试使用以下 routeEnhancers 使 URL 正常工作。

routeEnhancers:
  FeusersPlugin:
    type: Extbase
    extension: MyFeusers
    plugin: Users
    #limitToPages: [3,7]
    defaultController: 'FrontendUser::list'
    defaults:
      company_title: ''
      department_title: ''
    routes:
      # Detail view:
      -
        routePath: '/{employee_title}'
        _controller: 'FrontendUser::show'
        _arguments: {'employee_title': 'frontendUser'}
      # List view
      -
        routePath: '{company_title}'
        _controller: 'FrontendUser::list'
        _arguments: {'company_title': 'company'}
      -
        routePath: 'department/{department_title}'
        _controller: 'FrontendUser::list'
        _arguments: {'department_title': 'department'}
    aspects:
      employee_title:
        type: PersistedPatternMapper
        tableName: fe_users
        routeFieldPattern: '^(?P<first_name>.+)-(?P<last_name>\d+)$'
        routeFieldResult: '{first_name}-{last_name}'
      company_title:
        type: StaticValueMapper
        map:
          name-of-company: 'Name of company'
          name-of-other-company: 'Name of other company'
      department_title:
        type: PersistedAliasMapper
        tableName: 'fe_users'
        routeFieldName: 'my_department'

不工作的部分:
/?tx_myfeusers_users[action]=list&tx_myfeusers_users[company]=Name of company&tx_myfeusers_users[controller]=FrontendUser&tx_myfeusers_users[department]=My department

=> 结果:/department/My%20department/?tx_myfeusers_users[company]==Name%20of%20company
=> 需要:name-of-company/department/My%20department/
=> 甚至更好 name-of-company/department/My-department/
=> 甚至更好 name-of-company/My-department/

工作部件:
/?tx_myfeusers_users[action]=list&tx_myfeusers_users[company]=Name of company&tx_myfeusers_users[controller]=FrontendUser
=> 结果:/name-of-company/
=> 期望:/name-of-company/ => 完美!

/?tx_myfeusers_users[action]=show&tx_myfeusers_users[controller]=FrontendUser&tx_myfeusers_users[frontendUser]=143
=> 结果:/firstname-lastname/
=> 期望:/firstname-lastname/ => 完美!

这是我的真实网址配置,对我有用:

'fixedPostVars' => array(

  'userDetailConfiguration' => array(

    array(
      'GETvar' => 'tx_myfeusers_users[company]',
      'valueMap' => array(
        'name-of-company' => 'Name of company',
        'name-of-other-company' => 'Name of other company'
      ),
      'noMatch' => 'bypass'
    ),
    array(
      'GETvar' => 'tx_myfeusers_users[action]',
      'valueMap' => array(
        'show' => '',
        'list' => '',
        'edit' => 'edit',
        'update' => 'update',
      ),
      'noMatch' => 'bypass'
    ),
    array(
      'GETvar' => 'tx_myfeusers_users[controller]',
      'valueMap' => array(
        'FrontendUser' => '',
      ),
      'noMatch' => 'bypass'
    ),
    array(
      'GETvar' => 'tx_myfeusers_users[frontendUser]',
      'lookUpTable' => array(
        'table' => 'fe_users',
        'id_field' => 'uid',
        'alias_field' => 'CONCAT(first_name, "-", last_name)',
        'useUniqueCache' => 1,
        'useUniqueCache_conf' => array(
          'strtolower' => 1,
          'spaceCharacter' => '-',
        ),
      ),
    ),
  ),

  '3' => 'userDetailConfiguration',

),
'postVarSets' => array(
  '_DEFAULT' => array(

    'department' => array(
      array(
        'GETvar' => 'tx_myfeusers_users[department]',
      ),
    ),

  ),
),

由于找不到其他方法让它工作,我为部门编写了自己的映射器:

ext_localconf.php中注册映射器:

$GLOBALS['TYPO3_CONF_VARS']
        ['SYS']
        ['routing']
        ['aspects']
        ['DepartmentStaticMapper'] = \Vendor\Extension\Routing\Aspect\DepartmentStaticMapper::class;

Classes/Routing/Aspect/DepartmentStaticMapper.php 中添加映射器 class 的文件。映射器什么都不做,但 returns 给定值:

<?php
namespace Vendor\Extension\Routing\Aspect;

use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;

class DepartmentStaticMapper implements StaticMappableAspectInterface
{
    /**
     * @var array
     */
    protected $settings;

    /**
     * @param array $settings
     * @throws \InvalidArgumentException
     */
    public function __construct(array $settings)
    {
        $this->settings = $settings;
    }

    /**
     * {@inheritdoc}
     */
    public function generate(string $value): ?string
    {
        return $value;
    }

    /**
     * {@inheritdoc}
     */
    public function resolve(string $value): ?string
    {
        return $value;
    }
}

最后在站点配置的 routeEnhancers 中使用映射器 DepartmentStaticMapper(以下配置的最后一行):

routeEnhancers:
  FeusersPlugin:
    type: Extbase
    extension: MyFeusers
    plugin: Users
    #limitToPages: [3,7]
    defaultController: 'FrontendUser::list'
    defaults:
      company_title: ''
      department_title: ''
    routes:
      # Detail view:
      -
        routePath: '{employee_title}'
        _controller: 'FrontendUser::show'
        _arguments: {'employee_title': 'frontendUser'}
      # List view
      -
        routePath: '{company_title}'
        _controller: 'FrontendUser::list'
        _arguments: {'company_title': 'company'}
      -
        routePath: 'department/{department_title}'
        _controller: 'FrontendUser::list'
        _arguments: {'department_title': 'department'}
    aspects:
      employee_title:
        type: PersistedPatternMapper
        tableName: fe_users
        routeFieldPattern: '^(?P<first_name>.+)-(?P<last_name>.+)$'
        routeFieldResult: '{first_name}-{last_name}'
      company_title:
        type: StaticValueMapper
        map:
          name-of-company: 'Name of company'
          name-of-other-company: 'Name of other company'
      department_title:
        type: DepartmentStaticMapper