Typo3 8.7.x/Extbase:在自己的扩展中扩展RealUrl



是否可以在我自己的扩展中扩展realurl配置?我尝试了以下操作,但不起作用:

//ext_localconf.php of my extension
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']['postVarSets']['_DEFAULT'] = array_merge($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']['postVarSets']['_DEFAULT'],
[
'gallery' => [
[
'GETvar' => 'tx_myext_p1gallery[gallery]',
'lookUpTable' => [
'table' => 'tx_myext_domain_model_gallery',
'id_field' => 'uid',
'alias_field' => 'title',
'maxLength' => 120,
'useUniqueCache' => 1,
'addWhereClause' => ' AND NOT deleted',
'enable404forInvalidAlias' => 1,
'autoUpdate' => 1,
'expireDays' => 5,
'useUniqueCache_conf' => [
'spaceCharacter' => '_'
]
]
],
],
'controller' => [
[
'GETvar' => 'tx_myext_p1gallery[action]',
'noMatch' => 'bypass',
],
[
'GETvar' => 'tx_myext_p1gallery[controller]',
'noMatch' => 'bypass',
],
[
'GETvar' => 'tx_myext_p1gallery[backId]',
'noMatch' => 'bypass',
],
],
]

);

如果我在realurl_conf.php中使用相同的代码,那么它就可以工作了。

RealURL有一个用于此目的的"autoconf"挂钩。

在您的ext_localconf.php中,您必须输入:

if (TYPO3CMSCoreUtilityExtensionManagementUtility::isLoaded('realurl')) {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/realurl/class.tx_realurl_autoconfgen.php']['extensionConfiguration']['my_extkey'] = VendorExtHooksRealUrlAutoConfiguration::class . '->addConfig';
}

你的课可能是这样的:

<?php
namespace VendorExtHooks;
class RealUrlAutoConfiguration
{
/**
* Generates additional RealURL configuration and merges it with provided configuration
*
* @param       array $params Default configuration
*
* @return      array Updated configuration
*/
public function addConfig($params)
{
return array_merge_recursive($params['config'], [
'postVarSets' => [
'_DEFAULT' => [
'gallery'    => [
[
'GETvar'      => 'tx_myext_p1gallery[gallery]',
'lookUpTable' => [
'table'                    => 'tx_myext_domain_model_gallery',
'id_field'                 => 'uid',
'alias_field'              => 'title',
'maxLength'                => 120,
'useUniqueCache'           => 1,
'addWhereClause'           => ' AND NOT deleted',
'enable404forInvalidAlias' => 1,
'autoUpdate'               => 1,
'expireDays'               => 5,
'useUniqueCache_conf'      => [
'spaceCharacter' => '_'
]
]
],
],
'controller' => [
[
'GETvar'  => 'tx_myext_p1gallery[action]',
'noMatch' => 'bypass',
],
[
'GETvar'  => 'tx_myext_p1gallery[controller]',
'noMatch' => 'bypass',
],
[
'GETvar'  => 'tx_myext_p1gallery[backId]',
'noMatch' => 'bypass',
],
],
]
]
]);
}
}

只有当您在RealURL扩展配置(在扩展管理器中(中激活了autoconf时,这才有效

您的修改可能太晚了,realurl无法考虑
Realurl在响应过程的早期执行。可能您的扩展在此之前不会执行。

由于realurl_config文件在您的控制之下(典型的:站点扩展(,并且它只是PHP,因此您还可以包含从"原始"realurl_conf.php进行的扩展修改。

if (file_exists('typo3conf/ext/my_extension/Configuration/realurl_additional_conf.php')) {
include_once('typo3conf/ext/my_extension/Configuration/realurl_additional_conf.php');
}

最新更新