UniqueValidator.php 715 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Model\Entity\Attribute;
  7. use Magento\Framework\DataObject;
  8. use Magento\Eav\Model\Entity\AbstractEntity;
  9. /**
  10. * Class for validate unique attribute value
  11. */
  12. class UniqueValidator implements UniqueValidationInterface
  13. {
  14. /**
  15. * @inheritdoc
  16. */
  17. public function validate(
  18. AbstractAttribute $attribute,
  19. DataObject $object,
  20. AbstractEntity $entity,
  21. $entityLinkField,
  22. array $entityIds
  23. ) {
  24. if (isset($entityIds[0])) {
  25. return $entityIds[0] == $object->getData($entityLinkField);
  26. }
  27. return true;
  28. }
  29. }