ElementVisibilityComposite.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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;
  7. use Magento\Framework\Exception\ConfigurationMismatchException;
  8. /**
  9. * Contains list of classes which implement ElementVisibilityInterface for
  10. * checking of visibility of form elements on Stores > Settings > Configuration page in Admin Panel.
  11. * @api
  12. * @since 101.0.0
  13. */
  14. class ElementVisibilityComposite implements ElementVisibilityInterface
  15. {
  16. /**
  17. * List of objects which implements ElementVisibilityInterface for
  18. * checking of visibility of form elements on Configuration page.
  19. *
  20. * @var ElementVisibilityInterface[]
  21. */
  22. private $visibility = [];
  23. /**
  24. * @param ElementVisibilityInterface[] $visibility List of objects which define visibility status of form elements
  25. * under its own conditions.
  26. * @throws ConfigurationMismatchException It is thrown if some object from list $visibility
  27. * implements the wrong interface.
  28. */
  29. public function __construct(array $visibility = [])
  30. {
  31. foreach ($visibility as $name => $item) {
  32. if (!$item instanceof ElementVisibilityInterface) {
  33. throw new ConfigurationMismatchException(
  34. __(
  35. '%1: Instance of %2 is expected, got %3 instead',
  36. $name,
  37. ElementVisibilityInterface::class,
  38. get_class($item)
  39. )
  40. );
  41. }
  42. }
  43. $this->visibility = $visibility;
  44. }
  45. /**
  46. * @inheritdoc
  47. * @since 101.0.0
  48. */
  49. public function isHidden($path)
  50. {
  51. foreach ($this->visibility as $element) {
  52. if ($element->isHidden($path)) {
  53. return true;
  54. }
  55. }
  56. return false;
  57. }
  58. /**
  59. * @inheritdoc
  60. * @since 101.0.0
  61. */
  62. public function isDisabled($path)
  63. {
  64. foreach ($this->visibility as $element) {
  65. if ($element->isDisabled($path)) {
  66. return true;
  67. }
  68. }
  69. return false;
  70. }
  71. }