storeManager = $storeManager; $this->scopeConfig = $scopeConfig; $this->fileStorageDatabase = $fileStorageDatabase; $this->mediaDirectory = $filesystem->getDirectoryRead(DirectoryList::MEDIA); } /** * @return string */ public function getFaviconFile() { if (null === $this->faviconFile) { $this->faviconFile = $this->prepareFaviconFile(); } return $this->faviconFile; } /** * @return string */ public function getDefaultFavicon() { return 'Magento_Theme::favicon.ico'; } /** * @return string */ protected function prepareFaviconFile() { $folderName = \Magento\Config\Model\Config\Backend\Image\Favicon::UPLOAD_DIR; $scopeConfig = $this->scopeConfig->getValue( 'design/head/shortcut_icon', \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); $path = $folderName . '/' . $scopeConfig; $faviconUrl = $this->storeManager->getStore() ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $path; if ($scopeConfig !== null && $this->checkIsFile($path)) { return $faviconUrl; } return false; } /** * If DB file storage is on - find there, otherwise - just file_exists * * @param string $filename relative file path * @return bool */ protected function checkIsFile($filename) { if ($this->fileStorageDatabase->checkDbUsage() && !$this->mediaDirectory->isFile($filename)) { $this->fileStorageDatabase->saveFileToFilesystem($filename); } return $this->mediaDirectory->isFile($filename); } }