Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
AbstractAction Class Reference
Inheritance diagram for AbstractAction:
Action AbstractAction ActionInterface Notification ListAction Action Auth Redirect Index System AbstractConfig Popup Auth User Role

Public Member Functions

 __construct (Action\Context $context)
 
 dispatch (\Magento\Framework\App\RequestInterface $request)
 
 _processUrlKeys ()
 
 getUrl ($route='', $params=[])
 
- Public Member Functions inherited from Action
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getActionFlag ()
 
- Public Member Functions inherited from AbstractAction
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getRequest ()
 
 getResponse ()
 
- Public Member Functions inherited from ActionInterface
 execute ()
 

Data Fields

const FLAG_IS_URLS_CHECKED = 'check_url_settings'
 
const SESSION_NAMESPACE = 'adminhtml'
 
const ADMIN_RESOURCE = 'Magento_Backend::admin'
 
- Data Fields inherited from ActionInterface
const FLAG_NO_DISPATCH = 'no-dispatch'
 
const FLAG_NO_POST_DISPATCH = 'no-postDispatch'
 
const FLAG_NO_DISPATCH_BLOCK_EVENT = 'no-beforeGenerateLayoutBlocksDispatch'
 
const PARAM_NAME_BASE64_URL = 'r64'
 
const PARAM_NAME_URL_ENCODED = 'uenc'
 

Protected Member Functions

 _isAllowed ()
 
 _getSession ()
 
 getMessageManager ()
 
 _addBreadcrumb ($label, $title, $link=null)
 
 _addContent (\Magento\Framework\View\Element\AbstractBlock $block)
 
 _addLeft (\Magento\Framework\View\Element\AbstractBlock $block)
 
 _addJs (\Magento\Framework\View\Element\AbstractBlock $block)
 
 _isUrlChecked ()
 
 _processLocaleSettings ()
 
 _redirect ($path, $arguments=[])
 
 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _validateSecretKey ()
 
- Protected Member Functions inherited from Action
 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _redirect ($path, $arguments=[])
 

Protected Attributes

 $_publicActions = []
 
 $_sessionNamespace = self::SESSION_NAMESPACE
 
 $_helper
 
 $_session
 
 $_authorization
 
 $_auth
 
 $_backendUrl
 
 $_localeResolver
 
 $_canUseBaseUrl
 
 $_formKeyValidator
 
- Protected Attributes inherited from Action
 $_objectManager
 
 $_sessionNamespace
 
 $_eventManager
 
 $_actionFlag
 
 $_redirect
 
 $_view
 
 $_url
 
 $messageManager
 
- Protected Attributes inherited from AbstractAction
 $_request
 
 $_response
 
 $resultRedirectFactory
 
 $resultFactory
 

Detailed Description

Generic backend controller

@api @SuppressWarnings(PHPMD.NumberOfChildren) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 16 of file AbstractAction.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Action\Context  $context)
Parameters
\Magento\Backend\App\Action\Context$context

Definition at line 90 of file AbstractAction.php.

91  {
92  parent::__construct($context);
93  $this->_authorization = $context->getAuthorization();
94  $this->_auth = $context->getAuth();
95  $this->_helper = $context->getHelper();
96  $this->_backendUrl = $context->getBackendUrl();
97  $this->_formKeyValidator = $context->getFormKeyValidator();
98  $this->_localeResolver = $context->getLocaleResolver();
99  $this->_canUseBaseUrl = $context->getCanUseBaseUrl();
100  $this->_session = $context->getSession();
101  }

Member Function Documentation

◆ _addBreadcrumb()

_addBreadcrumb (   $label,
  $title,
  $link = null 
)
protected
Parameters
string$label
string$title
string | null$link
Returns
$this

Definition at line 154 of file AbstractAction.php.

155  {
156  $this->_view->getLayout()->getBlock('breadcrumbs')->addLink($label, $title, $link);
157  return $this;
158  }
$title
Definition: default.phtml:14
$label
Definition: details.phtml:21

◆ _addContent()

_addContent ( \Magento\Framework\View\Element\AbstractBlock  $block)
protected
Parameters
\Magento\Framework\View\Element\AbstractBlock$block
Returns
$this

Definition at line 164 of file AbstractAction.php.

165  {
166  return $this->_moveBlockToContainer($block, 'content');
167  }
$block
Definition: block.php:8

◆ _addJs()

_addJs ( \Magento\Framework\View\Element\AbstractBlock  $block)
protected
Parameters
\Magento\Framework\View\Element\AbstractBlock$block
Returns
$this

Definition at line 182 of file AbstractAction.php.

183  {
184  return $this->_moveBlockToContainer($block, 'js');
185  }
$block
Definition: block.php:8

◆ _addLeft()

_addLeft ( \Magento\Framework\View\Element\AbstractBlock  $block)
protected
Parameters
\Magento\Framework\View\Element\AbstractBlock$block
Returns
$this

Definition at line 173 of file AbstractAction.php.

174  {
175  return $this->_moveBlockToContainer($block, 'left');
176  }
$block
Definition: block.php:8

◆ _forward()

_forward (   $action,
  $controller = null,
  $module = null,
array  $params = null 
)
protected

Forward to action

@TODO MAGETWO-28356: Refactor controller actions to new ResultInterface

Parameters
string$action
string | null$controller
string | null$module
array | null$params
Returns
void

Definition at line 333 of file AbstractAction.php.

334  {
335  $this->_getSession()->setIsUrlNotice($this->_actionFlag->get('', self::FLAG_IS_URLS_CHECKED));
336  return parent::_forward($action, $controller, $module, $params);
337  }
$controller
Definition: info.phtml:14
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ _getSession()

_getSession ( )
protected

Retrieve adminhtml session model object

Returns
\Magento\Backend\Model\Session

Definition at line 116 of file AbstractAction.php.

◆ _isAllowed()

_isAllowed ( )
protected
Returns
bool

Definition at line 106 of file AbstractAction.php.

107  {
108  return $this->_authorization->isAllowed(static::ADMIN_RESOURCE);
109  }

◆ _isUrlChecked()

_isUrlChecked ( )
protected

Check whether url is checked

Returns
bool

Definition at line 239 of file AbstractAction.php.

240  {
241  return !$this->_actionFlag->get('', self::FLAG_IS_URLS_CHECKED)
242  && !$this->getRequest()->isForwarded()
243  && !$this->_getSession()->getIsUrlNotice(true)
245  }

◆ _processLocaleSettings()

_processLocaleSettings ( )
protected

Set session locale, process force locale set through url params

Returns
$this

Definition at line 294 of file AbstractAction.php.

295  {
296  $forceLocale = $this->getRequest()->getParam('locale', null);
297  if ($this->_objectManager->get(\Magento\Framework\Validator\Locale::class)->isValid($forceLocale)) {
298  $this->_getSession()->setSessionLocale($forceLocale);
299  }
300 
301  if ($this->_getSession()->getLocale() === null) {
302  $this->_getSession()->setLocale($this->_localeResolver->getLocale());
303  }
304 
305  return $this;
306  }

◆ _processUrlKeys()

_processUrlKeys ( )

Check url keys. If non valid - redirect

Returns
bool
See also
\Magento\Backend\App\Request\BackendValidator for default request validation.

Definition at line 255 of file AbstractAction.php.

256  {
257  $_isValidFormKey = true;
258  $_isValidSecretKey = true;
259  $_keyErrorMsg = '';
260  if ($this->_auth->isLoggedIn()) {
261  if ($this->getRequest()->isPost()) {
262  $_isValidFormKey = $this->_formKeyValidator->validate($this->getRequest());
263  $_keyErrorMsg = __('Invalid Form Key. Please refresh the page.');
264  } elseif ($this->_backendUrl->useSecretKey()) {
265  $_isValidSecretKey = $this->_validateSecretKey();
266  $_keyErrorMsg = __('You entered an invalid Secret Key. Please refresh the page.');
267  }
268  }
269  if (!$_isValidFormKey || !$_isValidSecretKey) {
270  $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
271  $this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
272  if ($this->getRequest()->getQuery('isAjax', false) || $this->getRequest()->getQuery('ajax', false)) {
273  $this->getResponse()->representJson(
274  $this->_objectManager->get(
275  \Magento\Framework\Json\Helper\Data::class
276  )->jsonEncode(
277  ['error' => true, 'message' => $_keyErrorMsg]
278  )
279  );
280  } else {
281  $this->_redirect($this->_backendUrl->getStartupPageUrl());
282  }
283  return false;
284  }
285  return true;
286  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13

◆ _redirect()

_redirect (   $path,
  $arguments = [] 
)
protected

Set redirect into response

@TODO MAGETWO-28356: Refactor controller actions to new ResultInterface

Parameters
string$path
array$arguments
Returns
\Magento\Framework\App\ResponseInterface

Definition at line 316 of file AbstractAction.php.

317  {
318  $this->_getSession()->setIsUrlNotice($this->_actionFlag->get('', self::FLAG_IS_URLS_CHECKED));
319  $this->getResponse()->setRedirect($this->getUrl($path, $arguments));
320  return $this->getResponse();
321  }
$arguments

◆ _validateSecretKey()

_validateSecretKey ( )
protected

Validate Secret Key

Returns
bool

Definition at line 356 of file AbstractAction.php.

357  {
358  if (is_array($this->_publicActions) && in_array($this->getRequest()->getActionName(), $this->_publicActions)) {
359  return true;
360  }
361 
362  $secretKey = $this->getRequest()->getParam(\Magento\Backend\Model\UrlInterface::SECRET_KEY_PARAM_NAME, null);
363  if (!$secretKey || $secretKey != $this->_backendUrl->getSecretKey()) {
364  return false;
365  }
366  return true;
367  }

◆ dispatch()

dispatch ( \Magento\Framework\App\RequestInterface  $request)
Parameters
\Magento\Framework\App\RequestInterface$request
Returns
\Magento\Framework\App\ResponseInterface

Definition at line 206 of file AbstractAction.php.

207  {
208  if ($request->isDispatched() && $request->getActionName() !== 'denied' && !$this->_isAllowed()) {
209  $this->_response->setStatusHeader(403, '1.1', 'Forbidden');
210  if (!$this->_auth->isLoggedIn()) {
211  return $this->_redirect('*/auth/login');
212  }
213  $this->_view->loadLayout(['default', 'adminhtml_denied'], true, true, false);
214  $this->_view->renderLayout();
215  $this->_request->setDispatched(true);
216 
217  return $this->_response;
218  }
219 
220  if ($this->_isUrlChecked()) {
221  $this->_actionFlag->set('', self::FLAG_IS_URLS_CHECKED, true);
222  }
223 
224  $this->_processLocaleSettings();
225 
226  // Need to preload isFirstPageAfterLogin (see https://github.com/magento/magento2/issues/15510)
227  if ($this->_auth->isLoggedIn()) {
228  $this->_auth->getAuthStorage()->isFirstPageAfterLogin();
229  }
230 
231  return parent::dispatch($request);
232  }

◆ getMessageManager()

getMessageManager ( )
protected
Returns
\Magento\Framework\Message\ManagerInterface

Definition at line 124 of file AbstractAction.php.

125  {
126  return $this->messageManager;
127  }

◆ getUrl()

getUrl (   $route = '',
  $params = [] 
)

Generate url by route and parameters

Parameters
string$route
array$params
Returns
string

Definition at line 346 of file AbstractAction.php.

347  {
348  return $this->_helper->getUrl($route, $params);
349  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

Field Documentation

◆ $_auth

$_auth
protected

Definition at line 65 of file AbstractAction.php.

◆ $_authorization

$_authorization
protected

Definition at line 60 of file AbstractAction.php.

◆ $_backendUrl

$_backendUrl
protected

Definition at line 70 of file AbstractAction.php.

◆ $_canUseBaseUrl

$_canUseBaseUrl
protected

Definition at line 80 of file AbstractAction.php.

◆ $_formKeyValidator

$_formKeyValidator
protected

Definition at line 85 of file AbstractAction.php.

◆ $_helper

$_helper
protected

Definition at line 50 of file AbstractAction.php.

◆ $_localeResolver

$_localeResolver
protected

Definition at line 75 of file AbstractAction.php.

◆ $_publicActions

$_publicActions = []
protected

Definition at line 38 of file AbstractAction.php.

◆ $_session

$_session
protected

Definition at line 55 of file AbstractAction.php.

◆ $_sessionNamespace

$_sessionNamespace = self::SESSION_NAMESPACE
protected

Definition at line 45 of file AbstractAction.php.

◆ ADMIN_RESOURCE

const ADMIN_RESOURCE = 'Magento_Backend::admin'

Authorization level of a basic admin session

Definition at line 31 of file AbstractAction.php.

◆ FLAG_IS_URLS_CHECKED

const FLAG_IS_URLS_CHECKED = 'check_url_settings'

Name of "is URLs checked" flag

Definition at line 21 of file AbstractAction.php.

◆ SESSION_NAMESPACE

const SESSION_NAMESPACE = 'adminhtml'

Session namespace to refer in other places

Definition at line 26 of file AbstractAction.php.


The documentation for this class was generated from the following file: