Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Backend\Helper;
7 
9 
16 class Data extends AbstractHelper
17 {
18  const XML_PATH_USE_CUSTOM_ADMIN_URL = 'admin/url/use_custom';
19 
23  protected $_pageHelpUrl;
24 
28  protected $_routeConfig;
29 
33  protected $_locale;
34 
38  protected $_backendUrl;
39 
43  protected $_auth;
44 
49 
53  protected $mathRandom;
54 
64  public function __construct(
65  \Magento\Framework\App\Helper\Context $context,
66  \Magento\Framework\App\Route\Config $routeConfig,
67  \Magento\Framework\Locale\ResolverInterface $locale,
68  \Magento\Backend\Model\UrlInterface $backendUrl,
69  \Magento\Backend\Model\Auth $auth,
70  \Magento\Backend\App\Area\FrontNameResolver $frontNameResolver,
71  \Magento\Framework\Math\Random $mathRandom
72  ) {
73  parent::__construct($context);
74  $this->_routeConfig = $routeConfig;
75  $this->_locale = $locale;
76  $this->_backendUrl = $backendUrl;
77  $this->_auth = $auth;
78  $this->_frontNameResolver = $frontNameResolver;
79  $this->mathRandom = $mathRandom;
80  }
81 
85  public function getPageHelpUrl()
86  {
87  if (!$this->_pageHelpUrl) {
88  $this->setPageHelpUrl();
89  }
90  return $this->_pageHelpUrl;
91  }
92 
97  public function setPageHelpUrl($url = null)
98  {
99  if ($url === null) {
101  $frontModule = $request->getControllerModule();
102  if (!$frontModule) {
103  $frontModule = $this->_routeConfig->getModulesByFrontName($request->getModuleName());
104  if (empty($frontModule) === false) {
105  $frontModule = $frontModule[0];
106  } else {
107  $frontModule = null;
108  }
109  }
110  $url = 'http://www.magentocommerce.com/gethelp/';
111  $url .= $this->_locale->getLocale() . '/';
112  $url .= $frontModule . '/';
113  $url .= $request->getControllerName() . '/';
114  $url .= $request->getActionName() . '/';
115 
116  $this->_pageHelpUrl = $url;
117  }
118  $this->_pageHelpUrl = $url;
119 
120  return $this;
121  }
122 
127  public function addPageHelpUrl($suffix)
128  {
129  $this->_pageHelpUrl = $this->getPageHelpUrl() . $suffix;
130  return $this;
131  }
132 
138  public function getUrl($route = '', $params = [])
139  {
140  return $this->_backendUrl->getUrl($route, $params);
141  }
142 
146  public function getCurrentUserId()
147  {
148  if ($this->_auth->getUser()) {
149  return $this->_auth->getUser()->getId();
150  }
151  return false;
152  }
153 
160  public function prepareFilterString($filterString)
161  {
162  $data = [];
163  $filterString = base64_decode($filterString);
164  parse_str($filterString, $data);
165  array_walk_recursive(
166  $data,
167  // @codingStandardsIgnoreStart
173  // @codingStandardsIgnoreEnd
174  function (&$value) {
175  $value = trim(rawurldecode($value));
176  }
177  );
178  return $data;
179  }
180 
187  {
188  return $this->mathRandom->getUniqueHash();
189  }
190 
196  public function getHomePageUrl()
197  {
198  return $this->_backendUrl->getRouteUrl('adminhtml');
199  }
200 
207  public function getAreaFrontName($checkHost = false)
208  {
209  return $this->_frontNameResolver->getFrontName($checkHost);
210  }
211 }
$suffix
Definition: name.phtml:27
const XML_PATH_USE_CUSTOM_ADMIN_URL
Definition: Data.php:18
getAreaFrontName($checkHost=false)
Definition: Data.php:207
$value
Definition: gender.phtml:16
getUrl($route='', $params=[])
Definition: Data.php:138
setPageHelpUrl($url=null)
Definition: Data.php:97
prepareFilterString($filterString)
Definition: Data.php:160
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\App\Route\Config $routeConfig, \Magento\Framework\Locale\ResolverInterface $locale, \Magento\Backend\Model\UrlInterface $backendUrl, \Magento\Backend\Model\Auth $auth, \Magento\Backend\App\Area\FrontNameResolver $frontNameResolver, \Magento\Framework\Math\Random $mathRandom)
Definition: Data.php:64
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18