Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DownloadCustomCss.php
Go to the documentation of this file.
1 <?php
8 
11 
17 {
23  public function execute()
24  {
25  $themeId = $this->getRequest()->getParam('theme_id');
26  try {
28  $themeFactory = $this->_objectManager->create(\Magento\Framework\View\Design\Theme\FlyweightFactory::class);
29  $theme = $themeFactory->create($themeId);
30  if (!$theme) {
31  throw new \InvalidArgumentException(sprintf('We cannot find a theme with id "%1".', $themeId));
32  }
33 
34  $customCssFiles = $theme->getCustomization()->getFilesByType(
35  \Magento\Theme\Model\Theme\Customization\File\CustomCss::TYPE
36  );
38  $customCssFile = reset($customCssFiles);
39  if ($customCssFile && $customCssFile->getContent()) {
40  return $this->_fileFactory->create(
41  $customCssFile->getFileName(),
42  ['type' => 'filename', 'value' => $customCssFile->getFullPath()],
43  DirectoryList::ROOT
44  );
45  }
46  } catch (\Exception $e) {
47  $this->messageManager->addException($e, __('We can\'t find file.'));
48  $this->getResponse()->setRedirect($this->_redirect->getRefererUrl());
49  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
50  }
51  }
52 }
__()
Definition: __.php:13
$theme