Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Gallery.php
Go to the documentation of this file.
1 <?php
14 
19 class Gallery extends \Magento\Catalog\Block\Product\View\Gallery
20 {
24  protected $mediaHelper;
25 
35  public function __construct(
36  \Magento\Catalog\Block\Product\Context $context,
37  \Magento\Framework\Stdlib\ArrayUtils $arrayUtils,
38  \Magento\Framework\Json\EncoderInterface $jsonEncoder,
39  \Magento\ProductVideo\Helper\Media $mediaHelper,
40  array $data = [],
41  \Magento\Catalog\Model\Product\Gallery\ImagesConfigFactoryInterface $imagesConfigFactory = null,
42  array $galleryImagesConfig = []
43  ) {
44  parent::__construct(
45  $context,
48  $data,
49  $imagesConfigFactory,
50  $galleryImagesConfig
51  );
52  $this->mediaHelper = $mediaHelper;
53  }
54 
60  public function getMediaGalleryDataJson()
61  {
62  $mediaGalleryData = [];
63  foreach ($this->getProduct()->getMediaGalleryImages() as $mediaGalleryImage) {
64  $mediaGalleryData[] = [
65  'mediaType' => $mediaGalleryImage->getMediaType(),
66  'videoUrl' => $mediaGalleryImage->getVideoUrl(),
67  'isBase' => $this->isMainImage($mediaGalleryImage),
68  ];
69  }
70  return $this->jsonEncoder->encode($mediaGalleryData);
71  }
72 
78  public function getVideoSettingsJson()
79  {
80  $videoSettingData[] = [
81  'playIfBase' => $this->mediaHelper->getPlayIfBaseAttribute(),
82  'showRelated' => $this->mediaHelper->getShowRelatedAttribute(),
83  'videoAutoRestart' => $this->mediaHelper->getVideoAutoRestartAttribute(),
84  ];
85  return $this->jsonEncoder->encode($videoSettingData);
86  }
87 
94  {
95  return $this->jsonEncoder->encode([]);
96  }
97 }