Container.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Component\Control;
  7. use Magento\Framework\View\Element\AbstractBlock;
  8. use Magento\Framework\View\Element\UiComponent\Control\ControlInterface;
  9. /**
  10. * Class Container
  11. */
  12. class Container extends AbstractBlock
  13. {
  14. /**
  15. * Default button class
  16. */
  17. const DEFAULT_CONTROL = \Magento\Ui\Component\Control\Button::class;
  18. const SPLIT_BUTTON = \Magento\Ui\Component\Control\SplitButton::class;
  19. /**
  20. * Create button renderer
  21. *
  22. * @param string $blockName
  23. * @param string $blockClassName
  24. * @return ControlInterface
  25. */
  26. protected function createButton($blockName, $blockClassName = null)
  27. {
  28. if (null === $blockClassName) {
  29. $blockClassName = static::DEFAULT_CONTROL;
  30. }
  31. return $this->getLayout()->createBlock($blockClassName, $blockName);
  32. }
  33. /**
  34. * Render element HTML
  35. *
  36. * @return string
  37. */
  38. protected function _toHtml()
  39. {
  40. /** @var Item $item */
  41. $item = $this->getButtonItem();
  42. $data = $item->getData();
  43. $contextPrefixName = $this->getData('context') ? ($this->getData('context')->getNameInLayout() . '-') : '';
  44. $block = $this->createButton(
  45. $contextPrefixName . $item->getId() . '-button',
  46. isset($data['class_name']) ? $data['class_name'] : null
  47. );
  48. $block->setData($data);
  49. return $block->toHtml();
  50. }
  51. }