diff --git a/Model/Configuration.php b/Model/Configuration.php index f9ed73c..386afa7 100644 --- a/Model/Configuration.php +++ b/Model/Configuration.php @@ -100,6 +100,14 @@ public function __construct( $this->storeManager = $storeManager; } + /** + * @return Cloud + */ + public function getStoreManager() + { + return $this->storeManager; + } + /** * @return Cloud */ @@ -150,7 +158,7 @@ public function getCdnSubdomainStatus() */ public function getUserPlatform() { - return sprintf(self::USER_PLATFORM_TEMPLATE, '1.6.3', '2.0.0'); + return sprintf(self::USER_PLATFORM_TEMPLATE, '1.6.4', '2.0.0'); } /** diff --git a/Model/Template/Filter.php b/Model/Template/Filter.php index c916eac..cca3bdc 100644 --- a/Model/Template/Filter.php +++ b/Model/Template/Filter.php @@ -2,105 +2,18 @@ namespace Cloudinary\Cloudinary\Model\Template; -use Cloudinary\Cloudinary\Core\Image\ImageFactory; -use Cloudinary\Cloudinary\Core\UrlGenerator; use Magento\Widget\Model\Template\Filter as WidgetFilter; class Filter extends WidgetFilter { /** - * @var ImageFactory - */ - private $imageFactory; - - /** - * @var UrlGenerator - */ - private $urlGenerator; - - /** - * @param \Magento\Framework\Stdlib\StringUtils $string - * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Framework\Escaper $escaper - * @param \Magento\Framework\View\Asset\Repository $assetRepo - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param \Magento\Variable\Model\VariableFactory $coreVariableFactory - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\View\LayoutInterface $layout - * @param \Magento\Framework\View\LayoutFactory $layoutFactory - * @param \Magento\Framework\App\State $appState - * @param \Magento\Framework\UrlInterface $urlModel - * @param \Pelago\Emogrifier $emogrifier - * @param \Magento\Email\Model\Source\Variables $configVariables - * @param \Magento\Widget\Model\ResourceModel\Widget $widgetResource - * @param \Magento\Widget\Model\Widget $widget - * @param ImageFactory $imageFactory - * @param UrlGenerator $urlGenerator - * @SuppressWarnings(PHPMD.ExcessiveParameterList) - */ - public function __construct( - \Magento\Framework\Stdlib\StringUtils $string, - \Psr\Log\LoggerInterface $logger, - \Magento\Framework\Escaper $escaper, - \Magento\Framework\View\Asset\Repository $assetRepo, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Variable\Model\VariableFactory $coreVariableFactory, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\View\LayoutInterface $layout, - \Magento\Framework\View\LayoutFactory $layoutFactory, - \Magento\Framework\App\State $appState, - \Magento\Framework\UrlInterface $urlModel, - \Pelago\Emogrifier $emogrifier, - \Magento\Email\Model\Source\Variables $configVariables, - \Magento\Widget\Model\ResourceModel\Widget $widgetResource, - \Magento\Widget\Model\Widget $widget, - ImageFactory $imageFactory, - UrlGenerator $urlGenerator - ) { - $this->imageFactory = $imageFactory; - $this->urlGenerator = $urlGenerator; - - parent::__construct( - $string, - $logger, - $escaper, - $assetRepo, - $scopeConfig, - $coreVariableFactory, - $storeManager, - $layout, - $layoutFactory, - $appState, - $urlModel, - $emogrifier, - $configVariables, - $widgetResource, - $widget - ); - } - - /** - * Retrieve media file URL directive + * Return associative array of parameters *exposing $this->getParameters(). * - * @param string[] $construction - * @return string + * @param string $value raw parameters + * @return array */ - public function mediaDirective($construction) + public function getParams($value) { - $params = $this->getParameters($construction[2]); - $storeManager = $this->_storeManager; - - $image = $this->imageFactory->build( - $params['url'], - function () use ($storeManager, $params) { - return sprintf( - '%s%s', - $storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA), - $params['url'] - ); - } - ); - - return $this->urlGenerator->generateFor($image); + return $this->getParameters($value); } } diff --git a/Plugin/Widget/Model/Template/Filter.php b/Plugin/Widget/Model/Template/Filter.php new file mode 100644 index 0000000..2e67cba --- /dev/null +++ b/Plugin/Widget/Model/Template/Filter.php @@ -0,0 +1,82 @@ +_storeManager = $storeManager; + $this->_imageFactory = $imageFactory; + $this->_urlGenerator = $urlGenerator; + $this->_cloudinaryWidgetFilter = $cloudinaryWidgetFilter; + } + + /** + * Around retrieve media file URL directive + * + * @param \Magento\Widget\Model\Template\Filter $widgetFilter + * @param callable $proceed + * @param string[] $construction + * @return string + */ + public function aroundMediaDirective(\Magento\Widget\Model\Template\Filter $widgetFilter, callable $proceed, $construction) + { + $params = $this->_cloudinaryWidgetFilter->getParams($construction[2]); + if (!isset($params['url'])) { + return $proceed($construction); + } + + $storeManager = $this->_storeManager; + + $image = $this->_imageFactory->build( + $params['url'], + function () use ($storeManager, $params) { + return sprintf( + '%s%s', + $storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA), + $params['url'] + ); + } + ); + + return $this->_urlGenerator->generateFor($image); + } +} diff --git a/composer.json b/composer.json index f6290f8..f8ecab8 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "cloudinary/cloudinary-magento2", "description": "Cloudinary Magento 2 Integration.", "type": "magento2-module", - "version": "1.6.3", + "version": "1.6.4", "minimum-stability": "dev", "license": "MIT", "repositories": { diff --git a/etc/di.xml b/etc/di.xml index de25382..75f85a1 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -35,8 +35,9 @@ - + + + diff --git a/etc/module.xml b/etc/module.xml index 6814263..6f38d9f 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - +