ConfigCondition.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\View\Layout;
  7. use Magento\Framework\View\Layout\Condition\VisibilityConditionInterface;
  8. use Magento\Framework\App\Config\ScopeConfigInterface;
  9. use Magento\Framework\App\ScopeResolverInterface;
  10. /**
  11. * Check that config flag is set to true,
  12. */
  13. class ConfigCondition implements VisibilityConditionInterface
  14. {
  15. /**
  16. * Unique name.
  17. */
  18. const NAME = 'ifconfig';
  19. /**
  20. * @var ScopeConfigInterface
  21. */
  22. protected $scopeConfig;
  23. /**
  24. * @var ScopeResolverInterface
  25. */
  26. protected $scopeResolver;
  27. /**
  28. * @var string|null
  29. */
  30. private $scopeType;
  31. /**
  32. * ConfigCondition constructor.
  33. *
  34. * @param ScopeConfigInterface $scopeConfig
  35. * @param ScopeResolverInterface $scopeResolver
  36. * @param string|null $scopeType
  37. */
  38. public function __construct(
  39. ScopeConfigInterface $scopeConfig,
  40. ScopeResolverInterface $scopeResolver,
  41. $scopeType = null
  42. ) {
  43. $this->scopeType = $scopeType;
  44. $this->scopeConfig = $scopeConfig;
  45. $this->scopeResolver = $scopeResolver;
  46. }
  47. /**
  48. * @inheritdoc
  49. */
  50. public function isVisible(array $arguments)
  51. {
  52. return $this->scopeConfig->isSetFlag(
  53. $arguments['configPath'],
  54. $this->scopeType,
  55. $this->scopeResolver->getScope()
  56. );
  57. }
  58. /**
  59. * @return string
  60. */
  61. public function getName()
  62. {
  63. return self::NAME;
  64. }
  65. }