Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExternalVideoEntryConverter.php
Go to the documentation of this file.
1 <?php
8 
12 use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryExtensionFactory;
13 
18 {
22  const MEDIA_TYPE_CODE = 'external-video';
23 
27  protected $videoEntryFactory;
28 
33 
40  public function __construct(
41  \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $mediaGalleryEntryFactory,
42  \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
43  \Magento\Framework\Api\Data\VideoContentInterfaceFactory $videoEntryFactory,
44  ProductAttributeMediaGalleryEntryExtensionFactory $mediaGalleryEntryExtensionFactory
45  ) {
46  parent::__construct($mediaGalleryEntryFactory, $dataObjectHelper);
47  $this->videoEntryFactory = $videoEntryFactory;
48  $this->mediaGalleryEntryExtensionFactory = $mediaGalleryEntryExtensionFactory;
49  }
50 
54  public function getMediaEntryType()
55  {
56  return self::MEDIA_TYPE_CODE;
57  }
58 
64  public function convertTo(Product $product, array $rowData)
65  {
66  $entry = parent::convertTo($product, $rowData);
67  $videoEntry = $this->videoEntryFactory->create();
68  $this->dataObjectHelper->populateWithArray(
69  $videoEntry,
70  $rowData,
71  \Magento\Framework\Api\Data\VideoContentInterface::class
72  );
73  $entryExtension = $this->mediaGalleryEntryExtensionFactory->create();
74  $entryExtension->setVideoContent($videoEntry);
75  $entry->setExtensionAttributes($entryExtension);
76  return $entry;
77  }
78 
83  {
84  $dataFromPreviewImageEntry = parent::convertFrom($entry);
85  $videoContent = $entry->getExtensionAttributes()->getVideoContent();
86  $entryArray = [
87  'video_provider' => $videoContent->getVideoProvider(),
88  'video_url' => $videoContent->getVideoUrl(),
89  'video_title' => $videoContent->getVideoTitle(),
90  'video_description' => $videoContent->getVideoDescription(),
91  'video_metadata' => $videoContent->getVideoMetadata(),
92  ];
93  $entryArray = array_merge($dataFromPreviewImageEntry, $entryArray);
94  return $entryArray;
95  }
96 }
__construct(\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterfaceFactory $mediaGalleryEntryFactory, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Framework\Api\Data\VideoContentInterfaceFactory $videoEntryFactory, ProductAttributeMediaGalleryEntryExtensionFactory $mediaGalleryEntryExtensionFactory)
$dataObjectHelper
$mediaGalleryEntryExtensionFactory
getMediaEntryType()
const MEDIA_TYPE_CODE
$videoEntryFactory
convertFrom(ProductAttributeMediaGalleryEntryInterface $entry)
$mediaGalleryEntryFactory
getExtensionAttributes()
convertTo(Product $product, array $rowData)