Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SingleFile.php
Go to the documentation of this file.
1 <?php
11 
13 {
17  protected $_fileService;
18 
22  public function __construct(\Magento\Framework\View\Design\Theme\Customization\FileInterface $fileService)
23  {
24  $this->_fileService = $fileService;
25  }
26 
34  public function update(\Magento\Framework\View\Design\ThemeInterface $themeModel, $fileContent)
35  {
36  $customFiles = $themeModel->getCustomization()->getFilesByType($this->_fileService->getType());
37  $customCss = reset($customFiles);
38  if (empty($fileContent) && $customCss) {
39  $customCss->delete();
40  return $customCss;
41  }
42  if (!$customCss) {
43  $customCss = $this->_fileService->create();
44  }
45  $customCss->setData('content', $fileContent);
46  $customCss->setTheme($themeModel);
47  $customCss->save();
48  return $customCss;
49  }
50 }
__construct(\Magento\Framework\View\Design\Theme\Customization\FileInterface $fileService)
Definition: SingleFile.php:22
update(\Magento\Framework\View\Design\ThemeInterface $themeModel, $fileContent)
Definition: SingleFile.php:34