23 $themeId = $this->
getRequest()->getParam(
'id');
25 $serviceModel = $this->_objectManager->get(\
Magento\
Theme\Model\Uploader\Service::class);
27 $themeFactory = $this->_objectManager->get(\
Magento\Framework\View\Design\
Theme\FlyweightFactory::class);
29 $jsService = $this->_objectManager->get(\
Magento\Framework\View\Design\
Theme\Customization\File\Js::class);
31 $theme = $themeFactory->create($themeId);
33 throw new \Magento\Framework\Exception\LocalizedException(
34 __(
'We cannot find a theme with id "%1".', $themeId)
37 $jsFileData = $serviceModel->uploadJsFile(
'js_files_uploader');
38 $jsFile = $jsService->create();
40 $jsFile->setFileName($jsFileData[
'filename']);
41 $jsFile->setData(
'content', $jsFileData[
'content']);
45 $customization = $this->_objectManager->create(
46 \
Magento\Framework\View\Design\
Theme\CustomizationInterface::class,
49 $customJsFiles = $customization->getFilesByType(
50 \
Magento\Framework\View\Design\
Theme\Customization\File\Js::TYPE
52 $result = [
'error' =>
false,
'files' => $customization->generateFileInfo($customJsFiles)];
53 }
catch (\
Magento\Framework\Exception\LocalizedException $e) {
54 $result = [
'error' =>
true,
'message' => $e->getMessage()];
55 }
catch (\Exception $e) {
56 $result = [
'error' =>
true,
'message' =>
__(
'We can\'t upload the JS file right now.')];
57 $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
60 $this->_objectManager->get(\
Magento\Framework\Json\Helper\Data::class)->jsonEncode(
$result)