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(

    $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(
        /** @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(
        '_secure' => $this->_request->isSecure()

But inside the backend $this->assetRepository returns a backend asset :( and result url looks like:


when I expect to get url like:


The question is: how to get the frontend asset for specific theme in the backend?

1 Answer 1


Add to custom helper this dependency

\Magento\Store\Model\App\Emulation $emulation,
$this->emulation = $emulation;

and then in code before fetching logo run this

$this->emulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true);

Once you finish what you wanted just restore original environment

  • Thank you, it works great. Please, update your answer with this line: $this->emulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true), becouse the "force" parameter is set as false by-default (in this case the method does not work for the default store: if ($storeId == $this->_storeManager->getStore()->getStoreId() && !$force) { return; } gyazo.com/882f14048dbe4455acf824de241ccbb3 ). Mar 15, 2017 at 10:44
  • @SiarheyUchukhlebau done
    – rafal-kos
    Mar 15, 2017 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.