【问题标题】:Typo3 8.7.x / Extbase: Extend RealUrl in own extensionTypo3 8.7.x / Extbase:在自己的扩展中扩展 RealUrl
【发布时间】:2018-11-07 10:57:09
【问题描述】:

是否可以在我自己的扩展中扩展 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 中使用相同的代码,那么它就可以工作了。

【问题讨论】:

    标签: php typo3 extbase typo3-8.x realurl


    【解决方案1】:

    为此,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 时才有效

    【讨论】:

      【解决方案2】:

      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');
      }
      

      【讨论】:

      • 好的,谢谢您的建议。我想在不修改原始 realurl conf 的情况下让它工作。目前,我正在谷歌搜索钩子。
      • 如前所述:realurl 的早期执行将使其变得困难。我最好的猜测:你可能会在 realurl 本身中寻找一个钩子。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-14
      相关资源
      最近更新 更多