/** * @param \Zend_File_Transfer_Adapter_Http|\Zend_Validate $object * @param \Magento\Catalog\Model\Product\Option $option * @param array $fileFullPath * @return \Zend_File_Transfer_Adapter_Http|\Zend_Validate $object * @throws \Magento\Framework\Exception\InputException */ protected function buildImageValidator($object, $option, $fileFullPath = null) { $dimensions = []; if ($option->getImageSizeX() > 0) { $dimensions['maxwidth'] = $option->getImageSizeX(); } if ($option->getImageSizeY() > 0) { $dimensions['maxheight'] = $option->getImageSizeY(); } if (count($dimensions) > 0) { if ($fileFullPath !== null && !$this->isImage($fileFullPath)) { throw new \Magento\Framework\Exception\InputException(__('File \'%1\' is not an image.', $option->getTitle())); } $object->addValidator(new \Zend_Validate_File_ImageSize($dimensions)); } // File extension $allowed = $this->parseExtensionsString($option->getFileExtension()); if ($allowed !== null) { $object->addValidator(new \Zend_Validate_File_Extension($allowed)); } else { $forbidden = $this->parseExtensionsString($this->getConfigData('forbidden_extensions')); if ($forbidden !== null) { $object->addValidator(new \Zend_Validate_File_ExcludeExtension($forbidden)); } } $object->addValidator(new \Zend_Validate_File_FilesSize(['max' => $this->fileSize->getMaxFileSize()])); return $object; }
/** * {@inheritdoc} */ protected function getCustomAttributes(\Magento\Catalog\Model\Product\Option $option) { return [Metadata::FILE_EXTENSION => $option->getFileExtension(), Metadata::IMAGE_SIZE_X => $option->getImageSizeX(), Metadata::IMAGE_SIZE_Y => $option->getImageSizeY()]; }