Accordion.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Block\Widget;
  7. /**
  8. * Magento_Backend accordion widget
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Accordion extends \Magento\Backend\Block\Widget
  14. {
  15. /**
  16. * @var string[]
  17. */
  18. protected $_items = [];
  19. /**
  20. * @var string
  21. */
  22. protected $_template = 'Magento_Backend::widget/accordion.phtml';
  23. /**
  24. * @return string[]
  25. */
  26. public function getItems()
  27. {
  28. return $this->_items;
  29. }
  30. /**
  31. * @param string $itemId
  32. * @param array $config
  33. * @return $this
  34. */
  35. public function addItem($itemId, $config)
  36. {
  37. $this->_items[$itemId] = $this->getLayout()->createBlock(
  38. \Magento\Backend\Block\Widget\Accordion\Item::class,
  39. $this->getNameInLayout() . '-' . $itemId
  40. )->setData(
  41. $config
  42. )->setAccordion(
  43. $this
  44. )->setId(
  45. $itemId
  46. );
  47. if (isset($config['content']) && $config['content'] instanceof \Magento\Framework\View\Element\AbstractBlock) {
  48. $this->_items[$itemId]->setChild($itemId . '_content', $config['content']);
  49. }
  50. $this->setChild($itemId, $this->_items[$itemId]);
  51. return $this;
  52. }
  53. }