Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RouteParamsResolver.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Store\Model\Store;
9 use \Magento\Store\Api\Data\StoreInterface;
10 use \Magento\Store\Model\ScopeInterface as StoreScopeInterface;
11 
16 {
20  protected $scopeConfig;
21 
25  protected $storeManager;
26 
31 
39  public function __construct(
40  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
41  \Magento\Store\Model\StoreManagerInterface $storeManager,
42  \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver
43  ) {
44  $this->scopeConfig = $scopeConfig;
45  $this->storeManager = $storeManager;
46  $this->queryParamsResolver = $queryParamsResolver;
47  }
48 
59  public function beforeSetRouteParams(
60  \Magento\Framework\Url\RouteParamsResolver $subject,
61  array $data,
62  $unsetOldParams = true
63  ) {
64  if (isset($data['_scope'])) {
65  $subject->setScope($data['_scope']);
66  unset($data['_scope']);
67  }
68  if (isset($data['_scope_to_url']) && (bool)$data['_scope_to_url'] === true) {
70  $currentScope = $subject->getScope();
71  $storeCode = $currentScope && $currentScope instanceof StoreInterface ?
72  $currentScope->getCode() :
73  $this->storeManager->getStore()->getCode();
74 
75  $useStoreInUrl = $this->scopeConfig->getValue(
77  StoreScopeInterface::SCOPE_STORE,
79  );
80 
81  if ($useStoreInUrl && !$this->storeManager->hasSingleStore()) {
82  $this->queryParamsResolver->setQueryParam('___store', $storeCode);
83  }
84  }
85  unset($data['_scope_to_url']);
86 
87  return [$data, $unsetOldParams];
88  }
89 }
__construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver)
$storeCode
Definition: indexer.php:15