From 0cca279fa1ad1290b099a47c663d596317c929a0 Mon Sep 17 00:00:00 2001 From: Erik Hansen Date: Mon, 16 Nov 2015 15:53:30 -0600 Subject: [PATCH] Fix generation of urls to switch to specific scopes --- Helper/Data.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Helper/Data.php b/Helper/Data.php index 4fa549f..a4383e1 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -12,16 +12,29 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper /** @var \Magento\Store\Model\StoreManagerInterface */ protected $storeManager; + /** + * Url Builder + * + * @var \Magento\Backend\Model\Url + */ + protected $urlBuilder; + /** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param \Magento\Backend\Model\Url $urlBuilder */ public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, + \Magento\Backend\Model\Url $urlBuilder ) { $this->storeManager = $storeManager; $this->context = $context; + // Ideally we would just retrieve the urlBuilder using $this->content->getUrlBuilder(), but since it retrieves + // an instance of \Magento\Framework\Url instead of \Magento\Backend\Model\Url, we must explicitly request it + // via DI. + $this->urlBuilder = $urlBuilder; } /** @@ -142,11 +155,11 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form $section = $form->getSectionCode(); switch($scope) { case 'website': - $url = $this->_context->getUrlBuilder()->getUrl( + $url = $this->urlBuilder->getUrl( '*/*/*', array( - 'section'=>$section, - 'website'=>$scopeId + 'section' => $section, + 'website' => $scopeId ) ); $scopeLabel = sprintf( @@ -159,12 +172,11 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form case 'store': $store = $this->storeManager->getStore($scopeId); $website = $store->getWebsite(); - $url = $this->_context->getUrlBuilder()->getUrl( + $url = $this->urlBuilder->getUrl( '*/*/*', array( 'section' => $section, - 'website' => $website->getCode(), - 'store' => $store->getCode() + 'store' => $store->getId() ) ); $scopeLabel = sprintf( @@ -182,4 +194,4 @@ public function formatOverriddenScopes(\Magento\Config\Block\System\Config\Form return $formatted; } -} \ No newline at end of file +}