0

Example:

http://localhost/admin/admin/user/edit/user_id/5/key/db1082c352e51cfb817ce0335dd060cf6e953568daf2da25cca24eadb04dc884/

I want to return 'db1082c352e51cfb817ce0335dd060cf6e953568daf2da25cca24eadb04dc884' from within a ViewModel method.

1 Answer 1

1

If you want to implement this with View Model you need to use Magento\Framework\UrlInterface

<?php
declare(strict_types=1);

namespace Acme\StackExchange\ViewModel\Adminhtml;

use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;

class UrlHelper implements ArgumentInterface
{
    protected UrlInterface $urlBuilder;

    public function __construct(UrlInterface $urlBuilder)
    {
        $this->urlBuilder = $urlBuilder;
    }

    public function getUrl(string $route = '', array $params = []): string
    {
        return $this->urlBuilder->getUrl($route, $params);
    }

    public function getAdminUserViewUrl(int $userId): string
    {
        return $this->getUrl('adminhtml/user/edit', ['user_id' => $userId]);
    }
}

Using

$viewModel->getAdminUserViewUrl((int)$userId);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.