Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Gallery Class Reference
Inheritance diagram for Gallery:
AbstractView AbstractProduct Template AbstractBlock DataObject BlockInterface Gallery

Public Member Functions

 __construct (Context $context, ArrayUtils $arrayUtils, EncoderInterface $jsonEncoder, array $data=[], ImagesConfigFactoryInterface $imagesConfigFactory=null, array $galleryImagesConfig=[], UrlBuilder $urlBuilder=null)
 
 getGalleryImages ()
 
 getMagnifier ()
 
 getBreakpoints ()
 
 getGalleryUrl ($image=null)
 
 isMainImage ($image)
 
 getImageAttribute ($imageId, $attributeName, $default=null)
 
- Public Member Functions inherited from AbstractView
 __construct (\Magento\Catalog\Block\Product\Context $context, \Magento\Framework\Stdlib\ArrayUtils $arrayUtils, array $data=[])
 
 getProduct ()
 
 decorateArray ($array, $prefix='decorated_', $forceSetAll=false)
 
- Public Member Functions inherited from AbstractProduct
 __construct (\Magento\Catalog\Block\Product\Context $context, array $data=[])
 
 getAddToCartUrl ($product, $additional=[])
 
 getSubmitUrl ($product, $additional=[])
 
 getAddToWishlistParams ($product)
 
 getAddToCompareUrl ()
 
 getMinimalQty ($product)
 
 getReviewsSummaryHtml (\Magento\Catalog\Model\Product $product, $templateType=false, $displayIfNoReviews=false)
 
 getProduct ()
 
 getProductUrl ($product, $additional=[])
 
 hasProductUrl ($product)
 
 getColumnCount ()
 
 addColumnCountLayoutDepend ($pageLayout, $columnCount)
 
 removeColumnCountLayoutDepend ($pageLayout)
 
 getColumnCountLayoutDepend ($pageLayout)
 
 getPageLayout ()
 
 getCanShowProductPrice ($product)
 
 displayProductStockStatus ()
 
 getRandomString ($length, $chars=null)
 
 getProductPrice (\Magento\Catalog\Model\Product $product)
 
 isRedirectToCartEnabled ()
 
 getProductDetailsHtml (\Magento\Catalog\Model\Product $product)
 
 getDetailsRenderer ($type=null)
 
 getImage ($product, $imageId, $attributes=[])
 
- Public Member Functions inherited from Template
 __construct (Template\Context $context, array $data=[])
 
 setTemplateContext ($templateContext)
 
 getTemplate ()
 
 setTemplate ($template)
 
 getTemplateFile ($template=null)
 
 getArea ()
 
 assign ($key, $value=null)
 
 fetchView ($fileName)
 
 getBaseUrl ()
 
 getObjectData (\Magento\Framework\DataObject $object, $key)
 
 getCacheKeyInfo ()
 
- Public Member Functions inherited from AbstractBlock
 __construct (\Magento\Framework\View\Element\Context $context, array $data=[])
 
 getJsLayout ()
 
 getRequest ()
 
 getParentBlock ()
 
 setLayout (\Magento\Framework\View\LayoutInterface $layout)
 
 getLayout ()
 
 setNameInLayout ($name)
 
 getChildNames ()
 
 setAttribute ($name, $value=null)
 
 setChild ($alias, $block)
 
 addChild ($alias, $block, $data=[])
 
 unsetChild ($alias)
 
 unsetCallChild ($alias, $callback, $result, $params)
 
 unsetChildren ()
 
 getChildBlock ($alias)
 
 getChildHtml ($alias='', $useCache=true)
 
 getChildChildHtml ($alias, $childChildAlias='', $useCache=true)
 
 getBlockHtml ($name)
 
 insert ($element, $siblingName=0, $after=true, $alias='')
 
 append ($element, $alias='')
 
 getGroupChildNames ($groupName)
 
 getChildData ($alias, $key='')
 
 getUiId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getJsId ($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
 
 getUrl ($route='', $params=[])
 
 getViewFileUrl ($fileId, array $params=[])
 
 formatDate ( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
 
 formatTime ( $time=null, $format=\IntlDateFormatter::SHORT, $showDate=false)
 
 getModuleName ()
 
 escapeHtml ($data, $allowedTags=null)
 
 escapeJs ($string)
 
 escapeHtmlAttr ($string, $escapeSingleQuote=true)
 
 escapeCss ($string)
 
 stripTags ($data, $allowableTags=null, $allowHtmlEntities=false)
 
 escapeUrl ($string)
 
 escapeXssInUrl ($data)
 
 escapeQuote ($data, $addSlashes=false)
 
 escapeJsQuote ($data, $quote='\'')
 
 getNameInLayout ()
 
 getCacheKeyInfo ()
 
 getCacheKey ()
 
 getVar ($name, $module=null)
 
 isScopePrivate ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from BlockInterface
 toHtml ()
 

Protected Attributes

 $configView
 
 $jsonEncoder
 
- Protected Attributes inherited from AbstractView
 $arrayUtils
 
- Protected Attributes inherited from AbstractProduct
 $_priceBlock = []
 
 $_useLinkForAsLowAs = true
 
 $_defaultColumnCount = 3
 
 $_columnCountLayoutDepend = []
 
 $_coreRegistry
 
 $_taxData
 
 $_catalogConfig
 
 $_mathRandom
 
 $_cartHelper
 
 $_wishlistHelper
 
 $_compareProduct
 
 $_imageHelper
 
 $reviewRenderer
 
 $stockRegistry
 
 $imageBuilder
 
- Protected Attributes inherited from Template
 $_viewVars = []
 
 $_baseUrl
 
 $_jsUrl
 
 $_allowSymlinks
 
 $_filesystem
 
 $_template
 
 $templateEnginePool
 
 $_storeManager
 
 $_appState
 
 $directory
 
 $templateContext
 
 $pageConfig
 
 $resolver
 
 $validator
 
- Protected Attributes inherited from AbstractBlock
 $_design
 
 $_session
 
 $_sidResolver
 
 $_nameInLayout
 
 $_layout
 
 $jsLayout = []
 
 $_request
 
 $_urlBuilder
 
 $_eventManager
 
 $_frontController
 
 $_assetRepo
 
 $_viewConfig
 
 $_cacheState
 
 $_logger
 
 $_escaper
 
 $filterManager
 
 $_localeDate
 
 $inlineTranslation
 
 $_isScopePrivate = false
 
 $_scopeConfig
 
 $_cache
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Public Member Functions inherited from AbstractBlock
static extractModuleName ($className)
 
- Data Fields inherited from Template
const XML_PATH_TEMPLATE_ALLOW_SYMLINK = 'dev/template/allow_symlink'
 
- Data Fields inherited from AbstractBlock
const CACHE_GROUP = \Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER
 
const CACHE_KEY_PREFIX = 'BLOCK_'
 
- Protected Member Functions inherited from AbstractProduct
 _addProductAttributesAndPrices (\Magento\Catalog\Model\ResourceModel\Product\Collection $collection)
 
 getDetailsRendererList ()
 
- Protected Member Functions inherited from Template
 _construct ()
 
 _toHtml ()
 
 getRootDirectory ()
 
 getMediaDirectory ()
 
- Protected Member Functions inherited from AbstractBlock
 _construct ()
 
 _prepareLayout ()
 
 _beforeToHtml ()
 
 _afterToHtml ($html)
 
 _toHtml ()
 
 _getNotFoundUrl ($route='', $params=['_direct'=> 'core/index/notFound'])
 
 getCacheTags ()
 
 getCacheLifetime ()
 
 _loadCache ()
 
 _saveCache ($data)
 
 _getSidPlaceholder ($cacheKey=null)
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Product gallery block

@api

Since
100.0.2

Definition at line 31 of file Gallery.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Context  $context,
ArrayUtils  $arrayUtils,
EncoderInterface  $jsonEncoder,
array  $data = [],
ImagesConfigFactoryInterface  $imagesConfigFactory = null,
array  $galleryImagesConfig = [],
UrlBuilder  $urlBuilder = null 
)
Parameters
Context$context
ArrayUtils$arrayUtils
EncoderInterface$jsonEncoder
array$data
ImagesConfigFactoryInterface | null$imagesConfigFactory
array$galleryImagesConfig
UrlBuilder | null$urlBuilder

Definition at line 67 of file Gallery.php.

75  {
76  parent::__construct($context, $arrayUtils, $data);
77  $this->jsonEncoder = $jsonEncoder;
78  $this->galleryImagesConfigFactory = $imagesConfigFactory ?: ObjectManager::getInstance()
79  ->get(ImagesConfigFactoryInterface::class);
80  $this->galleryImagesConfig = $galleryImagesConfig;
81  $this->imageUrlBuilder = $urlBuilder ?? ObjectManager::getInstance()->get(UrlBuilder::class);
82  }

Member Function Documentation

◆ getBreakpoints()

getBreakpoints ( )

Return breakpoints options

Returns
string

Definition at line 125 of file Gallery.php.

126  {
127  return $this->jsonEncoder->encode($this->getVar('breakpoints'));
128  }

◆ getGalleryImages()

getGalleryImages ( )

Retrieve collection of gallery images

Returns
Collection

Definition at line 89 of file Gallery.php.

90  {
91  $product = $this->getProduct();
92  $images = $product->getMediaGalleryImages();
93  if (!$images instanceof \Magento\Framework\Data\Collection) {
94  return $images;
95  }
96 
97  foreach ($images as $image) {
98  $galleryImagesConfig = $this->getGalleryImagesConfig()->getItems();
99  foreach ($galleryImagesConfig as $imageConfig) {
100  $image->setData(
101  $imageConfig->getData('data_object_key'),
102  $this->imageUrlBuilder->getUrl($image->getFile(), $imageConfig['image_id'])
103  );
104  }
105  }
106 
107  return $images;
108  }

◆ getGalleryUrl()

getGalleryUrl (   $image = null)

Retrieve gallery url

Parameters
null | \Magento\Framework\DataObject$image
Returns
string

Definition at line 179 of file Gallery.php.

180  {
181  $params = ['id' => $this->getProduct()->getId()];
182  if ($image) {
183  $params['image'] = $image->getValueId();
184  }
185  return $this->getUrl('catalog/product/gallery', $params);
186  }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ getImageAttribute()

getImageAttribute (   $imageId,
  $attributeName,
  $default = null 
)

Returns image attribute

Parameters
string$imageId
string$attributeName
string$default
Returns
string

Definition at line 208 of file Gallery.php.

209  {
210  $attributes =
211  $this->getConfigView()->getMediaAttributes('Magento_Catalog', Image::MEDIA_TYPE_CONFIG_NODE, $imageId);
212  return $attributes[$attributeName] ?? $default;
213  }
$attributes
Definition: matrix.phtml:13

◆ getMagnifier()

getMagnifier ( )

Return magnifier options

Returns
string

Definition at line 115 of file Gallery.php.

116  {
117  return $this->jsonEncoder->encode($this->getVar('magnifier'));
118  }

◆ isMainImage()

isMainImage (   $image)

Is product main image

Parameters
\Magento\Framework\DataObject$image
Returns
bool

Definition at line 194 of file Gallery.php.

195  {
196  $product = $this->getProduct();
197  return $product->getImage() == $image->getFile();
198  }

Field Documentation

◆ $configView

$configView
protected

Definition at line 36 of file Gallery.php.

◆ $jsonEncoder

$jsonEncoder
protected

Definition at line 41 of file Gallery.php.


The documentation for this class was generated from the following file: