【问题标题】:How to use customEnhancer for plugin in TYPO3 version 9如何在 TYPO3 版本 9 中使用 customEnhancer 插件
【发布时间】:2019-03-18 07:10:21
【问题描述】:

我的网址是

backPid=5&tx_viextendednews_newsblog%5Baction%5D=show&tx_viextendednews_newsblog%5Bcontroller%5D=Extendednews&tx_viextendednews_newsblog%5Bextendednews%5D=1

我想成功

/news-detail/newstitle/?backpid=5

我写在我的 ext_local.conf 文件中 $GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['CustomPlugin'] = \VrisiniInfotechLLP\ViExtendednews\Routing\CustomEnhancer::class;

我的客户增强器是

class CustomEnhancer extends AbstractEnhancer implements RoutingEnhancerInterface, ResultingInterface
{
  /**
  * @var array
  */
  protected $configuration;

  /**
  * @var string
  */
  protected $namespace;
  public function __construct(array $configuration)
 {
    $this->configuration = $configuration;
    $this->namespace = $this->configuration['namespace'] ?? '';
 }
}

我的 config.yaml 路径是 /siteroot/typo3conf/sites/文件夹名/config.yaml

routeEnhancers:
NewsPlugin:
type: Extbase
limitToPages: [13]
extension: Extendednews
plugin: newsblog
routes:
  - { routePath: '/detail/{news_title}', _controller:   'Extendednews::show', _arguments: {'news_title': 'news'} }
defaultController: 'Extendednews::show'
aspects:
  news_title:
    type: PersistedAliasMapper
    tableName: 'tx_news_domain_model_news'
    routeFieldName: 'path_segment'
    routeValuePrefix: '/'

我怎么知道这个文件在内部工作? 现在我的问题是我应该在这个文件中写什么,以便获得所需的 url?

【问题讨论】:

    标签: router typo3-extensions realurl typo3-9.x


    【解决方案1】:

    我将以下代码用于自己的路由方面。 使用 DebuggerUtility::var_dump($value) 查看这个 Aspect 类中发生了什么:

        <?php
        namespace VENDOR\MyExtension\Routing\Aspect;
    
        use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
        use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;
        use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
    
        class IdentifierValueMapper implements StaticMappableAspectInterface
        {
            use SiteLanguageAwareTrait;
    
            /**
             * {@inheritdoc}
             */
            public function generate(string $value): ?string
            {
                return $value !== false ? (string)$value : null;
            }
    
            /**
             * {@inheritdoc}
             */
            public function resolve(string $value): ?string
            {
                return isset($value) ? (string)$value : null;
            }
        }
    

    config.yaml

        defaults:
          identifierPlaceholder: ''
        requirements:
          identifierPlaceholder: '^[a-zA-Z0-9]{32}$'
        aspects:
          identifierPlaceholder:
            type: IdentifierValueMapper
    

    localconf.php

        // Custom Routing Aspects Mapper
        $GLOBALS['TYPO3_CONF_VARS']['SYS']['routing']['aspects']['IdentifierValueMapper'] = \VENDOR\MyExtension\Routing\Aspect\IdentifierValueMapper::class;
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多