AjaxBlock.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Backend\Controller\Adminhtml\Dashboard;
  8. class AjaxBlock extends \Magento\Backend\Controller\Adminhtml\Dashboard
  9. {
  10. /**
  11. * @var \Magento\Framework\Controller\Result\RawFactory
  12. */
  13. protected $resultRawFactory;
  14. /**
  15. * @var \Magento\Framework\View\LayoutFactory
  16. */
  17. protected $layoutFactory;
  18. /**
  19. * @param \Magento\Backend\App\Action\Context $context
  20. * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
  21. * @param \Magento\Framework\View\LayoutFactory $layoutFactory
  22. */
  23. public function __construct(
  24. \Magento\Backend\App\Action\Context $context,
  25. \Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
  26. \Magento\Framework\View\LayoutFactory $layoutFactory
  27. ) {
  28. parent::__construct($context);
  29. $this->resultRawFactory = $resultRawFactory;
  30. $this->layoutFactory = $layoutFactory;
  31. }
  32. /**
  33. * @return \Magento\Framework\Controller\Result\Raw
  34. */
  35. public function execute()
  36. {
  37. $output = '';
  38. $blockTab = $this->getRequest()->getParam('block');
  39. $blockClassSuffix = str_replace(
  40. ' ',
  41. '\\',
  42. ucwords(str_replace('_', ' ', $blockTab))
  43. );
  44. if (in_array($blockTab, ['tab_orders', 'tab_amounts', 'totals'])) {
  45. $output = $this->layoutFactory->create()
  46. ->createBlock('Magento\\Backend\\Block\\Dashboard\\' . $blockClassSuffix)
  47. ->toHtml();
  48. }
  49. /** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
  50. $resultRaw = $this->resultRawFactory->create();
  51. return $resultRaw->setContents($output);
  52. }
  53. }