Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed 24990: link doesn't redirect to dashboard #26100

15 changes: 9 additions & 6 deletions setup/src/Magento/Setup/Controller/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
*/
namespace Magento\Setup\Controller;

use Magento\Backend\Model\UrlInterface;
use Magento\Setup\Exception;
use Magento\Setup\Model\Cron\Status;
use Magento\Setup\Model\Navigation as NavModel;
use Magento\Setup\Model\ObjectManagerProvider;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
use Zend\View\Model\ViewModel;
use Magento\Setup\Model\Cron\Status;
use Magento\Setup\Model\ObjectManagerProvider;

/**
* Class Navigation
Expand Down Expand Up @@ -47,7 +49,7 @@ public function __construct(NavModel $navigation, Status $status, ObjectManagerP
$this->navigation = $navigation;
$this->status = $status;
$this->objectManagerProvider = $objectManagerProvider;
$this->view = new ViewModel;
$this->view = new ViewModel();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you instantiating classes with new instead of using Factory or just Dependency Injection?

Copy link
Contributor Author

@Usik2203 Usik2203 Feb 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot create through Factory or Dependency Injection as usual I am getting such error
Screenshot 2020-02-18 at 10 28 44
Also I see a lot of cases in setup/src/Magento/Setup/Controller were these object was created with new

$this->view->setVariable('menu', $this->navigation->getMenuItems());
$this->view->setVariable('main', $this->navigation->getMainItems());
}
Expand All @@ -57,7 +59,7 @@ public function __construct(NavModel $navigation, Status $status, ObjectManagerP
*/
public function indexAction()
{
$json = new JsonModel;
$json = new JsonModel();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you instantiating classes with new instead of using Factory or just Dependency Injection?

$json->setVariable('nav', $this->navigation->getData());
$json->setVariable('menu', $this->navigation->getMenuItems());
$json->setVariable('main', $this->navigation->getMainItems());
Expand All @@ -79,11 +81,12 @@ public function menuAction()

/**
* @return array|ViewModel
* @throws Exception
*/
public function sideMenuAction()
{
/** @var \Magento\Backend\Model\UrlInterface $backendUrl */
$backendUrl = $this->objectManagerProvider->get()->get(\Magento\Backend\Model\UrlInterface::class);
/** @var UrlInterface $backendUrl */
$backendUrl = $this->objectManagerProvider->get()->get(UrlInterface::class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should inject that class to the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lbajsarowicz ,
Unfortunately I can't inject \Magento\Backend\Model\UrlInterfacedirectly to constructor. I get such error.
Screenshot 2020-02-03 at 18 24 27

Also I want to notice that construction like this $this->objectManagerProvider->get() is used in a lot of cases.

If such approach is wrong, maybe You could advise me something ?

Thanks a lot!


$this->view->setTemplate('/magento/setup/navigation/side-menu.phtml');
$this->view->setVariable('isInstaller', $this->navigation->getType() == NavModel::NAV_INSTALLER);
Expand Down