ConverterUtils.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Ui\Config;
  7. /**
  8. * Utility methods for converters
  9. */
  10. class ConverterUtils
  11. {
  12. /**
  13. * Retrieve component name
  14. *
  15. * @param \DOMNode $node
  16. * @return string
  17. */
  18. public function getComponentName(\DOMNode $node)
  19. {
  20. $result = $node->localName;
  21. if (!$node->hasAttributes()) {
  22. return $result;
  23. }
  24. foreach ($node->attributes as $attribute) {
  25. if ($attribute->name == Converter::NAME_ATTRIBUTE_KEY) {
  26. $result = $attribute->value;
  27. break;
  28. }
  29. }
  30. return $result;
  31. }
  32. /**
  33. * Check that $node is UiComponent
  34. *
  35. * If $node has 'settings', 'formElements' node in any parent node that it is not UiComponent
  36. *
  37. * @param \DOMNode $node
  38. * @return boolean
  39. */
  40. public function isUiComponent(\DOMNode $node)
  41. {
  42. if (in_array($node->localName, [Converter::SETTINGS_KEY, 'formElements'])) {
  43. return false;
  44. } elseif ($node->parentNode !== null) {
  45. return $this->isUiComponent($node->parentNode);
  46. }
  47. return true;
  48. }
  49. }