I'm trying to get url of the front-end logo inside a custom helper method in the backend, but I get stuck on getting a file using theme model. All I have is: store id, theme id, theme model and a filename:
/**
* Retrieve default store logo image URL from design config or theme
*
* @param null $storeId
* @return string
*/
protected function getDefaultStoreLogoUrl($storeId = null)
{
$folderName = \Magento\Config\Model\Config\Backend\Image\Logo::UPLOAD_DIR;
$storeLogoPath = $this->scopeConfig->getValue(
'design/header/logo_src',
ScopeInterface::SCOPE_STORE,
$storeId
);
$path = $folderName . '/' . $storeLogoPath;
$logoUrl = $this->_urlBuilder
->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]) . $path;
if ($storeLogoPath !== null && $this->isFile($path)) {
$url = $logoUrl;
} else {
$themeId = (int)$this->scopeConfig->getValue(
'design/theme/theme_id',
ScopeInterface::SCOPE_STORE,
$storeId
);
/** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection */
$themeCollection = $this->themeFactory->create();
/** @var \Magento\Theme\Model\Theme $theme */
$theme = $themeCollection->getItemById($themeId);
// ..... I'm stuck here
}
return $url;
}
I need asset for the theme frontend, but I don't know how to access it. It's should be something similar to the Block/Logo
's code:
$url = $this->assetRepository->getUrlWithParams(
'images/logo.svg',
[
'_secure' => $this->_request->isSecure()
]
);
But inside the backend $this->assetRepository
returns a backend asset :( and result url looks like:
http://baseurl.com/pub/static/adminhtml/Magento/backend/en_US/images/logo.svg
when I expect to get url like:
http://baseurl.com/pub/static/frontend/Magento/luma/en_US/images/logo.svg
The question is: how to get the frontend asset for specific theme in the backend?