Render.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Controller\Index;
  7. use Magento\Backend\App\Action\Context;
  8. use Magento\Framework\View\Element\UiComponentFactory;
  9. use Magento\Framework\View\Element\UiComponentInterface;
  10. /**
  11. * Is responsible for providing ui components information on store front
  12. */
  13. class Render extends \Magento\Framework\App\Action\Action
  14. {
  15. /**
  16. * @var Context
  17. */
  18. private $context;
  19. /**
  20. * @var UiComponentFactory
  21. */
  22. private $uiComponentFactory;
  23. /**
  24. * Render constructor.
  25. * @param Context $context
  26. * @param UiComponentFactory $uiComponentFactory
  27. */
  28. public function __construct(Context $context, UiComponentFactory $uiComponentFactory)
  29. {
  30. parent::__construct($context);
  31. $this->context = $context;
  32. $this->uiComponentFactory = $uiComponentFactory;
  33. }
  34. /**
  35. * Action for AJAX request
  36. *
  37. * @return void
  38. */
  39. public function execute()
  40. {
  41. if ($this->_request->getParam('namespace') === null) {
  42. $this->_redirect('noroute');
  43. return;
  44. }
  45. $component = $this->uiComponentFactory->create($this->_request->getParam('namespace'));
  46. $this->prepareComponent($component);
  47. $this->_response->appendBody((string) $component->render());
  48. }
  49. /**
  50. * Call prepare method in the component UI
  51. *
  52. * @param UiComponentInterface $component
  53. * @return void
  54. */
  55. private function prepareComponent(UiComponentInterface $component)
  56. {
  57. foreach ($component->getChildComponents() as $child) {
  58. $this->prepareComponent($child);
  59. }
  60. $component->prepare();
  61. }
  62. }