-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Extracted logic from wysiwyg OnInsert controller to a model #29677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ages to the content from media gallery instead of original images - Extract logic from controller to a model to enable before plugin interception of parameters
Hi @jmonteros422. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
@magento run all tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pull request @jmonteros422 ! Please see my comments.
I have removed the information about relation from this PR as it can be processed independently, ASI PR should still keep the relation information (until this PR is merged)
Also please cover the extracted model with an integration test
*/ | ||
public function __construct( | ||
\Magento\Backend\App\Action\Context $context, | ||
\Magento\Framework\Registry $coreRegistry, | ||
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory | ||
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory, | ||
\Magento\Cms\Model\Wysiwyg\Images\PrepareImage $prepareImage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the constructor dependency in a backwards-compatible way.
See "Adding a constructor parameter" section of https://devdocs.magento.com/contributor-guide/backward-compatible-development/
use Magento\Catalog\Helper\Data; | ||
use Magento\Cms\Helper\Wysiwyg\Images as ImagesHelper; | ||
|
||
class PrepareImage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make the class name more meaningful
class PrepareImage | |
class GetInsertImageContent |
/** | ||
* @var \Magento\Cms\Model\Wysiwyg\Images\PrepareImage | ||
*/ | ||
protected $prepareImage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected $prepareImage; | |
protected $getInsterImageContent; |
$image = $imagesHelper->getImageHtmlDeclaration($filename, $asIs); | ||
} | ||
/** @var \Magento\Cms\Model\Wysiwyg\Images\PrepareImage $image */ | ||
$image = $this->prepareImage->execute($request->getParams()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd avoid one-use variables like $image
} else { | ||
$image = $imagesHelper->getImageHtmlDeclaration($filename, $asIs); | ||
} | ||
/** @var \Magento\Cms\Model\Wysiwyg\Images\PrepareImage $image */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect and not necessary annotation. $image
is a string and that is already defined as a return type of called method
public function execute(array $data): string | ||
{ | ||
$filename = $this->imagesHelper->idDecode($data['filename']); | ||
$storeId = (int)$data['store_id']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Store id value was previously retrieved from store
field
* @param array $data | ||
* @return string | ||
*/ | ||
public function execute(array $data): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to have the meaningful parameters:
public function execute(array $data): string | |
public function execute(string $endcodedFilename, int $storeId, bool $forceStaticPath, bool $renderAsTag): string |
$filename = $this->imagesHelper->idDecode($data['filename']); | ||
$storeId = (int)$data['store_id']; | ||
|
||
$this->catalogHelper->setStoreId($storeId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please check why this call to catalog helper is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sivaschenko , did a check on different store view with and without that call and seems to not change anything on the rendered text in the content. I just included it on the model to not miss anything out from the original class. Let me know your thoughts.
if ($data['force_static_path']) { | ||
// phpcs:ignore Magento2.Functions.DiscouragedFunction | ||
$image = parse_url($this->imagesHelper->getCurrentUrl() . $filename, PHP_URL_PATH); | ||
} else { | ||
$image = $this->imagesHelper->getImageHtmlDeclaration($filename, $data['as_is']); | ||
} | ||
|
||
return $image; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible to remove unnecessary variable and simplify the code
if ($data['force_static_path']) { | |
// phpcs:ignore Magento2.Functions.DiscouragedFunction | |
$image = parse_url($this->imagesHelper->getCurrentUrl() . $filename, PHP_URL_PATH); | |
} else { | |
$image = $this->imagesHelper->getImageHtmlDeclaration($filename, $data['as_is']); | |
} | |
return $image; | |
if ($data['force_static_path']) { | |
// phpcs:ignore Magento2.Functions.DiscouragedFunction | |
return parse_url($this->imagesHelper->getCurrentUrl() . $filename, PHP_URL_PATH); | |
} | |
return $this->imagesHelper->getImageHtmlDeclaration($filename, $data['as_is']); |
…content from media gallery instead of original images - Extracted logic from wysiwyg OnInsert controller to a model
@magento run all tests |
…to-the-content-from-media-gallery-instead-of-original-images
… a model to enable before plugin interception of parameters - Test failure fixes. Made store_id parameter optional.
@magento run all tests |
… a model to enable before plugin interception of parameters - Fix static test
@magento run all tests |
…Insert controller to a model - Integration test
@magento run Functional Tests B2B |
Previous tests failed as they have been triggered from dependent ASI PR |
@magento run all tests |
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory | ||
* @var GetInsertImageContent | ||
*/ | ||
protected $getInsertImageContent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be private.
Pull Request state was updated. Re-review required.
@magento run all tests |
…to-the-content-from-media-gallery-instead-of-original-images
@magento run all tests |
Hi @jmonteros422, thank you for your contribution! |
Description (*)
This PR Extracts logic from Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\OnInsert::execute() controller to Magento\Cms\Model\Wysiwyg\Images\PrepareImage::execute() model
Dependent ASI Pull Request
PR: magento/adobe-stock-integration#1756
Fixed Issues
Fixes magento/adobe-stock-integration#1504: [2.1-develop] Insert rendition images to the content from media gallery instead of original images