Container.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Block\Widget\Button\Toolbar;
  7. use Magento\Backend\Block\Widget\Button\ContextInterface;
  8. /**
  9. * @method \Magento\Backend\Block\Widget\Button\Item getButtonItem()
  10. * @method ContextInterface getContext()
  11. * @method ContextInterface setContext(ContextInterface $context)
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class Container extends \Magento\Framework\View\Element\AbstractBlock
  16. {
  17. /**
  18. * Create button renderer
  19. *
  20. * @param string $blockName
  21. * @param string $blockClassName
  22. * @return \Magento\Backend\Block\Widget\Button
  23. */
  24. protected function createButton($blockName, $blockClassName = null)
  25. {
  26. if (null === $blockClassName) {
  27. $blockClassName = \Magento\Backend\Block\Widget\Button::class;
  28. }
  29. return $this->getLayout()->createBlock($blockClassName, $blockName);
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. protected function _toHtml()
  35. {
  36. $item = $this->getButtonItem();
  37. $context = $this->getContext();
  38. if ($item && $context && $context->canRender($item)) {
  39. $data = $item->getData();
  40. $blockClassName = isset($data['class_name']) ? $data['class_name'] : null;
  41. $buttonName = $this->getContext()->getNameInLayout() . '-' . $item->getId() . '-button';
  42. $block = $this->createButton($buttonName, $blockClassName);
  43. $block->setData($data);
  44. return $block->toHtml();
  45. }
  46. return parent::_toHtml();
  47. }
  48. }