Georgio
Georgio

Reputation: 175

How generate cHash to use for URL for an href in an <a> in own ViewHelper

I have to create a tag in a ViewHelper in my own extension, but I don't know how to do it, that it works with Typo3. It has to use for an anchor element, but this anchor is only a small part of the ViewHelper. This is the URL:

/sonstiges/test?tx_review_listreviews[action]=list&tx_review_listreviews[controller]=Reviews

For which part I have to create the cHash?

And how can I create the cHash inside the Viewhelper?

clyssCan I use md5?

Is there any function which I use inside the ViewHelper class?

A example would be great!

Upvotes: 0

Views: 63

Answers (1)

Georgio
Georgio

Reputation: 175

Finally I found a solution in Typo3, which I included into my viewHelper:

`<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\MyClass;

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Mvc\RequestInterface;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;

final class MyClass
{
public function __construct(
    private readonly UriBuilder $uriBuilder,
) {}

public function doSomething()
{
    $this->uriBuilder->setRequest($this->getExtbaseRequest());

    $url = $this->uriBuilder
        ->reset()
        ->setTargetPageUid(42)
        ->uriFor(
            'myAction',
            [
                'myRecord' => 21,
            ],
            'MyController',
            'myextension',
            'myplugin',
        );

    // do something with $url
}

private function getExtbaseRequest(): RequestInterface
{
    /** @var ServerRequestInterface $request */
    $request = $GLOBALS['TYPO3_REQUEST'];

    // We have to provide an Extbase request object
    return new Request(
        $request->withAttribute('extbase', new ExtbaseRequestParameters()),
    );
}

} `

Upvotes: 0

Related Questions