context = $context; $this->scopeConfig = $scopeConfig; $this->assetRepo = $assetRepo; $this->type = $type; } /** * {@inheritdoc} */ public function getUrl() { if ($this->getFilePath() !== null) { $result = $this->context->getBaseUrl() . '/' . $this->getModule() . '/' . $this->getFilePath(); } else { $result = $this->assetRepo->getUrl("Magento_Catalog::images/product/placeholder/{$this->type}.jpg"); } return $result; } /** * {@inheritdoc} */ public function getContentType() { return $this->contentType; } /** * {@inheritdoc} */ public function getPath() { if ($this->getFilePath() !== null) { $result = $this->getContext()->getPath() . DIRECTORY_SEPARATOR . $this->getModule() . DIRECTORY_SEPARATOR . $this->getFilePath(); } else { $defaultPlaceholder = $this->assetRepo->createAsset( "Magento_Catalog::images/product/placeholder/{$this->type}.jpg" ); try { $result = $defaultPlaceholder->getSourceFile(); } catch (NotFoundException $e) { $result = null; } } return $result; } /** * {@inheritdoc} */ public function getSourceFile() { return $this->getPath(); } /** * Get source content type * * @return string */ public function getSourceContentType() { return $this->contentType; } /** * {@inheritdoc} */ public function getContent() { return null; } /** * {@inheritdoc} */ public function getFilePath() { if ($this->filePath !== null) { return $this->filePath; } // check if placeholder defined in config $isConfigPlaceholder = $this->scopeConfig->getValue( "catalog/placeholder/{$this->type}_placeholder", \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); $this->filePath = $isConfigPlaceholder; return $this->filePath; } /** * {@inheritdoc} * @return ContextInterface */ public function getContext() { return $this->context; } /** * {@inheritdoc} */ public function getModule() { return 'placeholder'; } }