简体   繁体   中英

Typo3 8.7.x / Extbase: Extend RealUrl in own extension

is it possible to extend realurl configuration in my own extension? I tried the following, but it's not working:

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

);

If I use the same code at my realurl_conf.php then it's working.

Your modification probably is much to late to be considered by realurl.
Realurl is executed very early in the response process. Probably your extension is not executed until then.

as the realurl_config file is under your control (typical: site extension) and it's only PHP you also can include your extension modification from the 'original' 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 has an "autoconf" hook for this purpose.

In your ext_localconf.php you have to put:

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

your class could look like this:

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

This only works if you have autoconf activated in the RealURL extension configuration (in the Extension manager)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM