3
votes

I am working on a TYPO3 website and I have an issue with the routing system.

I have an extension which is based on data I query via ElasticSearch. Those data contains a field called "permalink", it is unique for every record in this index. I want to have a route with this field.

If I do something like this :

Event:
type: Extbase
limitToPages: [155]
extension: ...
plugin: ...
routes:
  -
    routePath: '/{idEvenement}'
    _controller: 'Event::show'
    _arguments:
      idEvenement: permalink

It does work but since Typo can't resolve the URL as unique, it adds cHash in it and I don't want that. I tried disabling the cHash generation for this field but I have issues if I go from one event to another (the URL changes but not its content until I clean the front cache).

I tried to use a custom aspect mapper but there is no documentation whatsoever and I don't know how it works. My route should become this (I guess) :

Event:
type: Extbase
limitToPages: [155]
extension: ...
plugin: ...
routes:
  -
    routePath: '/{idEvenement}'
    _controller: 'Event::show'
    _arguments:
      idEvenement: permalink
aspects:
  idEvenement:
    type: EventMapper

My EventMapper is currently this :

<?php

namespace Vendor\Extension\Routing\Aspect;

use TYPO3\CMS\Core\Routing\Aspect\StaticMappableAspectInterface;
use TYPO3\CMS\Core\Site\SiteLanguageAwareTrait;

class EventMapper implements StaticMappableAspectInterface
{
    use SiteLanguageAwareTrait;

    /**
     * {@inheritdoc}
     */
    public function generate(string $value): ?string
    {
        return $value;
    }

    /**
     * {@inheritdoc}
     */
    public function resolve(string $value): ?string
    {
        return isset($value) ? (string)$value : null;
    }
}

If I let this mapper in this state, I get an error in my Show action saying that the parameter is null.

1

1 Answers

1
votes

Ok I'm just stupid. Permalink is the name of the field in ElasticSearch but my action controller is waiting for a "idEvent" parameter. Which is why it's null... Sorry for the inconvenience.

So to clarify what I do : I somewhat fool Typo with my custom aspect. Normally its point is to check that the record is unique by sending the right information to the controller. In my case, I know for a fact that every record is unique (because my unique id is generated by Elastic). So the only thing I do is send back the id so that the controller can do its thing.