-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLOUDINARY-33: v1.6.4, In order to support Magento 2.3 & also apply b…
…est practices - Removed the di override for \Magento\Widget\Model\Template\Filter & Built a plugin for that instead.
- Loading branch information
pini-girit
committed
Dec 6, 2018
1 parent
290f332
commit 18ad1fe
Showing
6 changed files
with
101 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Cloudinary\Cloudinary\Plugin\Widget\Model\Template; | ||
|
||
use Cloudinary\Cloudinary\Core\Image\ImageFactory; | ||
use Cloudinary\Cloudinary\Core\UrlGenerator; | ||
use Cloudinary\Cloudinary\Model\Template\Filter as CloudinaryWidgetFilter; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
/** | ||
* Plugin for Template Filter Model | ||
*/ | ||
class Filter | ||
{ | ||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
protected $_storeManager; | ||
/** | ||
* @var ImageFactory | ||
*/ | ||
protected $_imageFactory; | ||
|
||
/** | ||
* @var UrlGenerator | ||
*/ | ||
protected $_urlGenerator; | ||
|
||
/** | ||
* @var CloudinaryWidgetFilter | ||
*/ | ||
protected $_cloudinaryWidgetFilter; | ||
|
||
/** | ||
* @param StoreManagerInterface $storeManager | ||
* @param ImageFactory $imageFactory | ||
* @param UrlGenerator $urlGenerator | ||
* @param CloudinaryWidgetFilter $cloudinaryWidgetFilter | ||
*/ | ||
public function __construct( | ||
StoreManagerInterface $storeManager, | ||
ImageFactory $imageFactory, | ||
UrlGenerator $urlGenerator, | ||
CloudinaryWidgetFilter $cloudinaryWidgetFilter | ||
) { | ||
$this->_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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters