Skip to content

Commit 18ad1fe

Browse files
author
pini-girit
committedDec 6, 2018
CLOUDINARY-33: v1.6.4, In order to support Magento 2.3 & also apply best practices - Removed the di override for \Magento\Widget\Model\Template\Filter & Built a plugin for that instead.
1 parent 290f332 commit 18ad1fe

File tree

6 files changed

+101
-97
lines changed

6 files changed

+101
-97
lines changed
 

‎Model/Configuration.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ public function __construct(
100100
$this->storeManager = $storeManager;
101101
}
102102

103+
/**
104+
* @return Cloud
105+
*/
106+
public function getStoreManager()
107+
{
108+
return $this->storeManager;
109+
}
110+
103111
/**
104112
* @return Cloud
105113
*/
@@ -150,7 +158,7 @@ public function getCdnSubdomainStatus()
150158
*/
151159
public function getUserPlatform()
152160
{
153-
return sprintf(self::USER_PLATFORM_TEMPLATE, '1.6.3', '2.0.0');
161+
return sprintf(self::USER_PLATFORM_TEMPLATE, '1.6.4', '2.0.0');
154162
}
155163

156164
/**

‎Model/Template/Filter.php

+5-92
Original file line numberDiff line numberDiff line change
@@ -2,105 +2,18 @@
22

33
namespace Cloudinary\Cloudinary\Model\Template;
44

5-
use Cloudinary\Cloudinary\Core\Image\ImageFactory;
6-
use Cloudinary\Cloudinary\Core\UrlGenerator;
75
use Magento\Widget\Model\Template\Filter as WidgetFilter;
86

97
class Filter extends WidgetFilter
108
{
119
/**
12-
* @var ImageFactory
13-
*/
14-
private $imageFactory;
15-
16-
/**
17-
* @var UrlGenerator
18-
*/
19-
private $urlGenerator;
20-
21-
/**
22-
* @param \Magento\Framework\Stdlib\StringUtils $string
23-
* @param \Psr\Log\LoggerInterface $logger
24-
* @param \Magento\Framework\Escaper $escaper
25-
* @param \Magento\Framework\View\Asset\Repository $assetRepo
26-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
27-
* @param \Magento\Variable\Model\VariableFactory $coreVariableFactory
28-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
29-
* @param \Magento\Framework\View\LayoutInterface $layout
30-
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
31-
* @param \Magento\Framework\App\State $appState
32-
* @param \Magento\Framework\UrlInterface $urlModel
33-
* @param \Pelago\Emogrifier $emogrifier
34-
* @param \Magento\Email\Model\Source\Variables $configVariables
35-
* @param \Magento\Widget\Model\ResourceModel\Widget $widgetResource
36-
* @param \Magento\Widget\Model\Widget $widget
37-
* @param ImageFactory $imageFactory
38-
* @param UrlGenerator $urlGenerator
39-
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
40-
*/
41-
public function __construct(
42-
\Magento\Framework\Stdlib\StringUtils $string,
43-
\Psr\Log\LoggerInterface $logger,
44-
\Magento\Framework\Escaper $escaper,
45-
\Magento\Framework\View\Asset\Repository $assetRepo,
46-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
47-
\Magento\Variable\Model\VariableFactory $coreVariableFactory,
48-
\Magento\Store\Model\StoreManagerInterface $storeManager,
49-
\Magento\Framework\View\LayoutInterface $layout,
50-
\Magento\Framework\View\LayoutFactory $layoutFactory,
51-
\Magento\Framework\App\State $appState,
52-
\Magento\Framework\UrlInterface $urlModel,
53-
\Pelago\Emogrifier $emogrifier,
54-
\Magento\Email\Model\Source\Variables $configVariables,
55-
\Magento\Widget\Model\ResourceModel\Widget $widgetResource,
56-
\Magento\Widget\Model\Widget $widget,
57-
ImageFactory $imageFactory,
58-
UrlGenerator $urlGenerator
59-
) {
60-
$this->imageFactory = $imageFactory;
61-
$this->urlGenerator = $urlGenerator;
62-
63-
parent::__construct(
64-
$string,
65-
$logger,
66-
$escaper,
67-
$assetRepo,
68-
$scopeConfig,
69-
$coreVariableFactory,
70-
$storeManager,
71-
$layout,
72-
$layoutFactory,
73-
$appState,
74-
$urlModel,
75-
$emogrifier,
76-
$configVariables,
77-
$widgetResource,
78-
$widget
79-
);
80-
}
81-
82-
/**
83-
* Retrieve media file URL directive
10+
* Return associative array of parameters *exposing $this->getParameters().
8411
*
85-
* @param string[] $construction
86-
* @return string
12+
* @param string $value raw parameters
13+
* @return array
8714
*/
88-
public function mediaDirective($construction)
15+
public function getParams($value)
8916
{
90-
$params = $this->getParameters($construction[2]);
91-
$storeManager = $this->_storeManager;
92-
93-
$image = $this->imageFactory->build(
94-
$params['url'],
95-
function () use ($storeManager, $params) {
96-
return sprintf(
97-
'%s%s',
98-
$storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA),
99-
$params['url']
100-
);
101-
}
102-
);
103-
104-
return $this->urlGenerator->generateFor($image);
17+
return $this->getParameters($value);
10518
}
10619
}
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
namespace Cloudinary\Cloudinary\Plugin\Widget\Model\Template;
4+
5+
use Cloudinary\Cloudinary\Core\Image\ImageFactory;
6+
use Cloudinary\Cloudinary\Core\UrlGenerator;
7+
use Cloudinary\Cloudinary\Model\Template\Filter as CloudinaryWidgetFilter;
8+
use Magento\Store\Model\StoreManagerInterface;
9+
10+
/**
11+
* Plugin for Template Filter Model
12+
*/
13+
class Filter
14+
{
15+
/**
16+
* @var StoreManagerInterface
17+
*/
18+
protected $_storeManager;
19+
/**
20+
* @var ImageFactory
21+
*/
22+
protected $_imageFactory;
23+
24+
/**
25+
* @var UrlGenerator
26+
*/
27+
protected $_urlGenerator;
28+
29+
/**
30+
* @var CloudinaryWidgetFilter
31+
*/
32+
protected $_cloudinaryWidgetFilter;
33+
34+
/**
35+
* @param StoreManagerInterface $storeManager
36+
* @param ImageFactory $imageFactory
37+
* @param UrlGenerator $urlGenerator
38+
* @param CloudinaryWidgetFilter $cloudinaryWidgetFilter
39+
*/
40+
public function __construct(
41+
StoreManagerInterface $storeManager,
42+
ImageFactory $imageFactory,
43+
UrlGenerator $urlGenerator,
44+
CloudinaryWidgetFilter $cloudinaryWidgetFilter
45+
) {
46+
$this->_storeManager = $storeManager;
47+
$this->_imageFactory = $imageFactory;
48+
$this->_urlGenerator = $urlGenerator;
49+
$this->_cloudinaryWidgetFilter = $cloudinaryWidgetFilter;
50+
}
51+
52+
/**
53+
* Around retrieve media file URL directive
54+
*
55+
* @param \Magento\Widget\Model\Template\Filter $widgetFilter
56+
* @param callable $proceed
57+
* @param string[] $construction
58+
* @return string
59+
*/
60+
public function aroundMediaDirective(\Magento\Widget\Model\Template\Filter $widgetFilter, callable $proceed, $construction)
61+
{
62+
$params = $this->_cloudinaryWidgetFilter->getParams($construction[2]);
63+
if (!isset($params['url'])) {
64+
return $proceed($construction);
65+
}
66+
67+
$storeManager = $this->_storeManager;
68+
69+
$image = $this->_imageFactory->build(
70+
$params['url'],
71+
function () use ($storeManager, $params) {
72+
return sprintf(
73+
'%s%s',
74+
$storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA),
75+
$params['url']
76+
);
77+
}
78+
);
79+
80+
return $this->_urlGenerator->generateFor($image);
81+
}
82+
}

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cloudinary/cloudinary-magento2",
33
"description": "Cloudinary Magento 2 Integration.",
44
"type": "magento2-module",
5-
"version": "1.6.3",
5+
"version": "1.6.4",
66
"minimum-stability": "dev",
77
"license": "MIT",
88
"repositories": {

‎etc/di.xml

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
<preference for="Cloudinary\Cloudinary\Core\AutoUploadMapping\AutoUploadConfigurationInterface"
3636
type="Cloudinary\Cloudinary\Model\AutoUploadMapping\AutoUploadConfiguration" />
3737

38-
<preference for="Magento\Widget\Model\Template\Filter"
39-
type="Cloudinary\Cloudinary\Model\Template\Filter" />
38+
<type name="Magento\Widget\Model\Template\Filter">
39+
<plugin name="cloudinary_plugin_widget_model_template_filter" type="Cloudinary\Cloudinary\Plugin\Widget\Model\Template\Filter" />
40+
</type>
4041

4142
<type name="Magento\Catalog\Helper\Image">
4243
<plugin name="cloudinary_image_helper_plugin" type="Cloudinary\Cloudinary\Plugin\ImageHelper" />

‎etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Cloudinary_Cloudinary" setup_version="1.6.3">
3+
<module name="Cloudinary_Cloudinary" setup_version="1.6.4">
44
<sequence>
55
<module name="Magento_ProductVideo"/>
66
</sequence>

0 commit comments

Comments
 (0)