AbstractRegisteredAction.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Controller\Adminhtml\Activation;
  6. use Magento\Backend\App\Action;
  7. use Magento\Backend\App\Action\Context;
  8. use Magento\Framework\App\RequestInterface;
  9. use Magento\Framework\App\ResponseInterface;
  10. use Temando\Shipping\Model\Config\ModuleConfigInterface;
  11. /**
  12. * Temando Activation Notice
  13. *
  14. * @package Temando\Shipping\Controller
  15. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  16. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  17. * @link http://www.temando.com/
  18. */
  19. abstract class AbstractRegisteredAction extends Action
  20. {
  21. /**
  22. * @var ModuleConfigInterface
  23. */
  24. private $config;
  25. /**
  26. * @param Context $context
  27. * @param ModuleConfigInterface $config
  28. */
  29. public function __construct(Context $context, ModuleConfigInterface $config)
  30. {
  31. $this->config = $config;
  32. parent::__construct($context);
  33. }
  34. /**
  35. * @param RequestInterface $request
  36. * @return ResponseInterface
  37. */
  38. public function dispatch(RequestInterface $request)
  39. {
  40. /** @var \Magento\Framework\App\Request\Http $request */
  41. if (!$this->config->isRegistered()) {
  42. $subject = $request->getControllerName();
  43. // only pass on the last part of the controller name.
  44. $delimiterPos = strpos($subject, '_');
  45. if ($delimiterPos !== false) {
  46. $subject = substr($subject, 1 + strpos($subject, '_'));
  47. }
  48. $this->_forward('notice', 'activation', $request->getModuleName(), [
  49. 'subject' => $subject
  50. ]);
  51. return $this->getResponse();
  52. }
  53. return parent::dispatch($request);
  54. }
  55. }