TYPO3:将fe_users realurl配置迁移到routeEnhancers

时间:2019-10-17 11:39:13

标签: routing typo3 typo3-9.x realurl

TYPO3:将fe_users realurl配置迁移到routeEnhancers

目前,我正在将TYPO3从版本8更新到9。到目前为止,我已经使用ext:realurl来生成语音URL。现在,我正在努力使“旧”网址与新的routeEnhancers一起使用。

我用自己的扩展名fe_users扩展了my_department表。现在,我正在尝试使用以下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/ =>完美!

这是我的realurl配置,对我有用:

'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]',
      ),
    ),

  ),
),

1 个答案:

答案 0 :(得分:0)

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

ext_localconf.php中注册映射器:

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

Classes/Routing/Aspect/DepartmentStaticMapper.php中为映射器类添加文件。映射器不执行任何操作,但返回给定值:

<?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;
    }
}

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

routeEnhancers