VideoExtractor.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\ProductVideo\Model;
  7. use Magento\ProductVideo\Helper\Media;
  8. class VideoExtractor implements \Magento\Framework\View\Xsd\Media\TypeDataExtractorInterface
  9. {
  10. /**
  11. * Media Entry type code
  12. */
  13. const MEDIA_TYPE_CODE = 'video';
  14. /**
  15. * Extract configuration data of videos from the DOM structure
  16. *
  17. * @param \DOMElement $mediaNode
  18. * @param string $mediaParentTag
  19. * @return array
  20. */
  21. public function process(\DOMElement $mediaNode, $mediaParentTag)
  22. {
  23. $result = [];
  24. $moduleNameVideo = $mediaNode->getAttribute('module');
  25. foreach ($mediaNode->getElementsByTagName(self::MEDIA_TYPE_CODE) as $node) {
  26. $videoId = $node->getAttribute('id');
  27. $result[$mediaParentTag][$moduleNameVideo][Media::MEDIA_TYPE_CONFIG_NODE][$videoId]['type']
  28. = $node->getAttribute('type');
  29. foreach ($node->childNodes as $attribute) {
  30. if ($attribute->nodeType != XML_ELEMENT_NODE) {
  31. continue;
  32. }
  33. $nodeValue = $attribute->nodeValue;
  34. $result[$mediaParentTag][$moduleNameVideo][Media::MEDIA_TYPE_CONFIG_NODE][$videoId][$attribute->tagName]
  35. = $nodeValue;
  36. }
  37. }
  38. return $result;
  39. }
  40. }