Previously my URL without implementing a custom mapper looked like this:
https:mydomain.com?tx_myextension%5Baction%5D=boat-action&tx_myextension%5BboatId%5D=boat-id&tx_myextension%5BboatName%5D=boat-name&tx_myextension%5Bcontroller%5D=boat-controller&cHash=hash
After the implementation of a custom URL mapper by extending the custom aspects I’ve reached this solution:?
https:mydomain.com/boat-name/boat-id
What I am trying to achieve is to hide the boat-id from the URL, the ID is not stored in a table and it is required from the pages to load the datas.
Html that generates the link
<f:link.action
class="call-to-action horizontal"
action=“boat-action”
controller=“boat-controller”
arguments="{
boatId: '{boat.id}',
boatName: '{boat.urlName}'
}"
pageUid="218"
>
config.yaml
routeEnhancers:
BoatName:
type: Extbase
limitToPages:
- 218
extension: myextension
plugin: Singleboat
routes:
- routePath: '/{boatName}/{boatId}'
_controller: Boat::boat-controller
aspects:
boatId:
type: BoatNameMapper
boatName:
type: BoatNameMapper
custom mapper class
class BoatNameMapper 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;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…