HtmlContent.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Component;
  7. use Magento\Framework\View\Element\BlockInterface;
  8. use Magento\Framework\View\Element\UiComponent\BlockWrapperInterface;
  9. use Magento\Framework\View\Element\UiComponent\ContextInterface;
  10. class HtmlContent extends AbstractComponent implements BlockWrapperInterface
  11. {
  12. const NAME = 'html_content';
  13. /**
  14. * @var BlockInterface
  15. */
  16. protected $block;
  17. /**
  18. * @param ContextInterface $context
  19. * @param BlockInterface $block
  20. * @param array $components
  21. * @param array $data
  22. */
  23. public function __construct(
  24. ContextInterface $context,
  25. BlockInterface $block,
  26. array $components = [],
  27. array $data = []
  28. ) {
  29. parent::__construct($context, $components, $data);
  30. $this->block = $block;
  31. }
  32. /**
  33. * Get wrapped block
  34. *
  35. * @return BlockInterface
  36. */
  37. public function getBlock()
  38. {
  39. return $this->block;
  40. }
  41. /**
  42. * Get component name
  43. *
  44. * @return string
  45. */
  46. public function getComponentName()
  47. {
  48. return static::NAME;
  49. }
  50. /**
  51. * @inheritDoc
  52. */
  53. public function render()
  54. {
  55. return $this->getData('config/content') ?: $this->block->toHtml();
  56. }
  57. /**
  58. * @inheritDoc
  59. */
  60. public function getConfiguration()
  61. {
  62. $configuration = parent::getConfiguration();
  63. if ($this->getData('wrapper/canShow') !== false) {
  64. if ($this->getData('isAjaxLoaded')) {
  65. $configuration['url'] = $this->getData('url');
  66. } else {
  67. if (!$this->getData('config/content')) { //add html block cony into cache
  68. $content = $this->block->toHtml();
  69. $this->addData(['config' => ['content' => $content]]);
  70. }
  71. $configuration['content'] = $this->getData('config/content');
  72. }
  73. if ($this->getData('wrapper')) {
  74. $configuration = array_merge($this->getData(), $this->getData('wrapper'));
  75. }
  76. }
  77. return $configuration;
  78. }
  79. }