_fileSizeService = $fileSize; $this->jsonEncoder = $jsonEncoder ?: ObjectManager::getInstance()->get(Json::class); $this->imageConfig = $imageConfig ?: ObjectManager::getInstance()->get(UploadConfigInterface::class); $this->imageUploadConfig = $imageUploadConfig ?: ObjectManager::getInstance()->get(UploadResizeConfigInterface::class); parent::__construct($context, $data); } /** * Initialize block. * * @return void */ protected function _construct() { parent::_construct(); $this->setId($this->getId() . '_Uploader'); $uploadUrl = $this->_urlBuilder->addSessionParam()->getUrl('adminhtml/*/upload'); $this->getConfig()->setUrl($uploadUrl); $this->getConfig()->setParams(['form_key' => $this->getFormKey()]); $this->getConfig()->setFileField('file'); $this->getConfig()->setFilters( [ 'images' => [ 'label' => __('Images (.gif, .jpg, .png)'), 'files' => ['*.gif', '*.jpg', '*.png'], ], 'media' => [ 'label' => __('Media (.avi, .flv, .swf)'), 'files' => ['*.avi', '*.flv', '*.swf'], ], 'all' => ['label' => __('All Files'), 'files' => ['*.*']], ] ); } /** * Get file size * * @return \Magento\Framework\File\Size */ public function getFileSizeService() { return $this->_fileSizeService; } /** * Get Image Upload Maximum Width Config. * * @return int * @since 100.2.7 */ public function getImageUploadMaxWidth() { return $this->imageUploadConfig->getMaxWidth(); } /** * Get Image Upload Maximum Height Config. * * @return int * @since 100.2.7 */ public function getImageUploadMaxHeight() { return $this->imageUploadConfig->getMaxHeight(); } /** * Prepares layout and set element renderer * * @return $this */ protected function _prepareLayout() { $this->pageConfig->addPageAsset('jquery/fileUploader/css/jquery.fileupload-ui.css'); return parent::_prepareLayout(); } /** * Retrieve uploader js object name * * @return string */ public function getJsObjectName() { return $this->getHtmlId() . 'JsObject'; } /** * Retrieve config json * * @return string */ public function getConfigJson() { return $this->jsonEncoder->encode($this->getConfig()->getData()); } /** * Retrieve config object * * @return \Magento\Framework\DataObject */ public function getConfig() { if (null === $this->_config) { $this->_config = new \Magento\Framework\DataObject(); } return $this->_config; } /** * Retrieve full uploader SWF's file URL * Implemented to solve problem with cross domain SWFs * Now uploader can be only in the same URL where backend located * * @param string $url url to uploader in current theme * @return string full URL */ public function getUploaderUrl($url) { return $this->_assetRepo->getUrl($url); } }