PropertyLocker.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Block\Adminhtml\Attribute;
  7. use Magento\Framework\Registry;
  8. use Magento\Eav\Model\Entity\Attribute\Config;
  9. /**
  10. * Disable form fields
  11. *
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. */
  14. class PropertyLocker
  15. {
  16. /**
  17. * @var Config
  18. */
  19. private $attributeConfig;
  20. /**
  21. * @var Registry
  22. */
  23. protected $registry;
  24. /**
  25. * @param Registry $registry
  26. * @param Config $attributeConfig
  27. * @codeCoverageIgnore
  28. */
  29. public function __construct(
  30. Registry $registry,
  31. Config $attributeConfig
  32. ) {
  33. $this->registry = $registry;
  34. $this->attributeConfig = $attributeConfig;
  35. }
  36. /**
  37. * @param \Magento\Framework\Data\Form $form
  38. * @return void
  39. */
  40. public function lock(\Magento\Framework\Data\Form $form)
  41. {
  42. /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attributeObject */
  43. $attributeObject = $this->registry->registry('entity_attribute');
  44. if ($attributeObject->getId()) {
  45. foreach ($this->attributeConfig->getLockedFields($attributeObject) as $field) {
  46. if ($element = $form->getElement($field)) {
  47. $element->setDisabled(1);
  48. $element->setReadonly(1);
  49. }
  50. }
  51. }
  52. }
  53. }