Php Typo3 8.7.x/Extbase:在自己的扩展中扩展RealUrl
是否可以在我自己的扩展中扩展realurl配置?我尝试了以下方法,但无效:Php Typo3 8.7.x/Extbase:在自己的扩展中扩展RealUrl,php,typo3,extbase,typo3-8.x,realurl,Php,Typo3,Extbase,Typo3 8.x,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']['postVarSet
//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考虑您的修改可能太晚了。 Realurl在响应过程的早期执行。可能直到那时才执行扩展 由于realurl_配置文件在您的控制下——典型的:站点扩展,并且它是唯一的PHP,因此您还可以包含来自“原始”realurl_conf.PHP的扩展修改
RealURL有一个用于此目的的autoconf钩子 在ext_localconf.php中,必须输入:
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('realurl')) {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/realurl/class.tx_realurl_autoconfgen.php']['extensionConfiguration']['my_extkey'] = \Vendor\Ext\Hooks\RealUrlAutoConfiguration::class . '->addConfig';
}
您的类可以如下所示:
<?php
namespace Vendor\Ext\Hooks;
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本身中寻找一个钩子。
<?php
namespace Vendor\Ext\Hooks;
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',
],
],
]
]
]);
}
}