TransWikia.com

Magento 2.3: Fatal error: Uncaught Error: Call to undefined method MagentoFrameworkViewElementUiComponentContext::getUrlBuilder()

Magento Asked by Partab Saifuddin Zakir on February 3, 2021

I’m new to Magento 2.3, I’m getting an error when I hit Add New Banner button, Grid is loading perfectly, error appear when i try to open form, I don’t know how to resolve this, BTW I copied this module and may be the module was running on Magento 2.1.

ERROR IMAGE

enter image description here

Code for /PHPCuong/BannerSlider/Block/Adminhtml/Banner/Edit/GenericButton.php

<?php

namespace PHPCuongBannerSliderBlockAdminhtmlBannerEdit;

use MagentoFrameworkViewElementUiComponentContext;
use MagentoFrameworkViewElementUiComponentControlButtonProviderInterface;

/**
 * Class GenericButton
 */
class GenericButton implements ButtonProviderInterface
{
    /**
     * @var Context
     */
    protected $context;

    /**
     * @var MagentoFrameworkAuthorizationInterface
     */
    protected $_authorization;

    /**
     * @param Context $context
     * @param MagentoFrameworkAuthorizationInterface $authorization
     */
    public function __construct(
        Context $context,
        MagentoFrameworkAuthorizationInterface $authorization
    ) {
        $this->context = $context;
        $this->_authorization = $authorization;
    }

    /**
     * Return the Banner ID
     *
     * @return int
     */
    public function getBannerId()
    {
        return (int)$this->context->getRequest()->getParam('id');
    }

    /**
     * Generate url by route and parameters
     *
     * @param   string $route
     * @param   array $params
     * @return  string
     */
    public function getUrl($route = '', $params = [])
    {
        return $this->context->getUrlBuilder()->getUrl($route, $params);
    }

    /**
     * {@inheritdoc}
     */
    public function getButtonData()
    {
        return [];
    }

    /**
     * Check permission for passed action
     *
     * @param string $resourceId
     * @return bool
     */
    protected function _isAllowedAction($resourceId)
    {
        return $this->_authorization->isAllowed($resourceId);
    }
}

2 Answers

I made some changes as follows and now it works for magento 2.4.1. Hope that helps

Code for /PHPCuong/BannerSlider/Block/Adminhtml/Banner/Edit/GenericButton.php

made changes to get id parameter from _request

/**
 * @param Context $context
 * @param MagentoFrameworkAuthorizationInterface $authorization
 */
public function __construct(
    Context $context,
    MagentoFrameworkAuthorizationInterface $authorization,
    MagentoFrameworkWebapiRestRequest $request  //<-- added 
) {
    $this->context = $context;
    $this->_authorization = $authorization;
    $this->_request = $request;  // <--added
}



 /**
 * Return the Group ID
 *
 * @return int
 */
public function getGroupId()
{
    //return (int)$this->context->getRequest()->getParam('id');
    return (int)$this->_request->getParams('id');  //<-- changed
}

Answered by mohitesachin217 on February 3, 2021

GetUrl has been rewritten slightly

https://github.com/magento/magento2/blob/2.3-develop/lib/internal/Magento/Framework/View/Element/UiComponent/Context.php#L364

   /**
     * @inheritdoc
     */
    public function getUrl($route = '', $params = [])
    {
        return $this->urlBuilder->getUrl($route, $params);
    }

Safest option would be to match this and inject @param UrlInterface $urlBuilder

You might even be able to simply use

return $this->context->getUrl($route, $params);

Answered by Dominic Xigen on February 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP