AbstractComposite.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Config\Model\Config\Structure\Element;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. abstract class AbstractComposite extends \Magento\Config\Model\Config\Structure\AbstractElement
  12. {
  13. /**
  14. * Child elements iterator
  15. *
  16. * @var Iterator
  17. */
  18. protected $_childrenIterator;
  19. /**
  20. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  21. * @param \Magento\Framework\Module\Manager $moduleManager
  22. * @param Iterator $childrenIterator
  23. */
  24. public function __construct(
  25. \Magento\Store\Model\StoreManagerInterface $storeManager,
  26. \Magento\Framework\Module\Manager $moduleManager,
  27. Iterator $childrenIterator
  28. ) {
  29. parent::__construct($storeManager, $moduleManager);
  30. $this->_childrenIterator = $childrenIterator;
  31. }
  32. /**
  33. * Set flyweight data
  34. *
  35. * @param array $data
  36. * @param string $scope
  37. * @return void
  38. */
  39. public function setData(array $data, $scope)
  40. {
  41. parent::setData($data, $scope);
  42. $children = array_key_exists(
  43. 'children',
  44. $this->_data
  45. ) && is_array(
  46. $this->_data['children']
  47. ) ? $this->_data['children'] : [];
  48. $this->_childrenIterator->setElements($children, $scope);
  49. }
  50. /**
  51. * Check whether element has visible child elements
  52. *
  53. * @return bool
  54. */
  55. public function hasChildren()
  56. {
  57. foreach ($this->getChildren() as $child) {
  58. return (bool)$child;
  59. }
  60. return false;
  61. }
  62. /**
  63. * Retrieve children iterator
  64. *
  65. * @return \Magento\Config\Model\Config\Structure\Element\Iterator
  66. */
  67. public function getChildren()
  68. {
  69. return $this->_childrenIterator;
  70. }
  71. /**
  72. * Check whether element is visible
  73. *
  74. * @return bool
  75. */
  76. public function isVisible()
  77. {
  78. if (parent::isVisible()) {
  79. return $this->hasChildren() || $this->getFrontendModel();
  80. }
  81. return false;
  82. }
  83. }