Converter.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Attributes configuration converter
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Eav\Model\Entity\Attribute\Config;
  9. class Converter implements \Magento\Framework\Config\ConverterInterface
  10. {
  11. /**
  12. * Convert config
  13. *
  14. * @param mixed $source
  15. * @return array
  16. */
  17. public function convert($source)
  18. {
  19. $output = [];
  20. /** @var \DOMNodeList $entities */
  21. $entities = $source->getElementsByTagName('entity');
  22. /** @var DOMNode $entity */
  23. foreach ($entities as $entity) {
  24. $entityConfig = [];
  25. $attributes = [];
  26. /** @var DOMNode $entityAttribute */
  27. foreach ($entity->getElementsByTagName('attribute') as $entityAttribute) {
  28. $attributeFields = [];
  29. foreach ($entityAttribute->getElementsByTagName('field') as $fieldData) {
  30. $locked = $fieldData->attributes->getNamedItem('locked')->nodeValue == "true" ? true : false;
  31. $attributeFields[$fieldData->attributes->getNamedItem(
  32. 'code'
  33. )->nodeValue] = [
  34. 'code' => $fieldData->attributes->getNamedItem('code')->nodeValue,
  35. 'locked' => $locked,
  36. ];
  37. }
  38. $attributes[$entityAttribute->attributes->getNamedItem('code')->nodeValue] = $attributeFields;
  39. }
  40. $entityConfig['attributes'] = $attributes;
  41. $output[$entity->attributes->getNamedItem('type')->nodeValue] = $entityConfig;
  42. }
  43. return $output;
  44. }
  45. }