Skip to content

Commit

Permalink
Merge pull request #7 from ubermanu/master
Browse files Browse the repository at this point in the history
Fix URL to the insert image action
  • Loading branch information
dmatthew authored May 2, 2019
2 parents c680319 + a5f8858 commit 93ad05f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore IDE files
/.idea
12 changes: 6 additions & 6 deletions Block/Adminhtml/Widget/Type/ImageChooser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class ImageChooser extends \Magento\Backend\Block\Template
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Data\Form\Element\Factory $elementFactory,
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Data\Form\Element\Factory $elementFactory,
$data = []
) {
$this->elementFactory = $elementFactory;
Expand All @@ -37,7 +37,7 @@ public function prepareElementHtml(AbstractElement $element)
$config = $this->_getData('config');
$onInsertUrl = $this->getUrl('dmatthew_widgets/wysiwyg_images/onInsert');
$sourceUrl = $this->getUrl('cms/wysiwyg_images/index',
['target_element_id' => $element->getId(), 'on_insert_url' => $onInsertUrl]);
['target_element_id' => $element->getId(), 'on_insert_url' => urlencode($onInsertUrl)]);

/** @var \Magento\Backend\Block\Widget\Button $chooser */
$chooser = $this->getLayout()->createBlock('Magento\Backend\Block\Widget\Button')
Expand All @@ -46,7 +46,7 @@ public function prepareElementHtml(AbstractElement $element)
->setLabel($config['button']['open'])
->setOnClick('MediabrowserUtility.openDialog(\'' . $sourceUrl . '\', 0, 0, "Insert File...", {})')
->setDisabled($element->getReadonly());

/** @var \Magento\Framework\Data\Form\Element\Text $input */
$input = $this->elementFactory->create("text", ['data' => $element->getData()]);
$input->setId($element->getId());
Expand All @@ -55,11 +55,11 @@ public function prepareElementHtml(AbstractElement $element)
if ($element->getRequired()) {
$input->addClass('required-entry');
}

$element->setData('after_element_html', $input->getElementHtml()
. $chooser->toHtml() . "<script>require(['mage/adminhtml/browser']);</script>");
$element->setValue(''); // Hides the additional label that gets added.

return $element;
}
}
16 changes: 15 additions & 1 deletion Block/Plugin/Adminhtml/Wysiwyg/Images/Content.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Dmatthew\WidgetParameters\Block\Plugin\Adminhtml\Wysiwyg\Images;

class Content
Expand All @@ -8,13 +9,26 @@ class Content
*/
private $request;

/**
* Content constructor.
*
* @param \Magento\Framework\App\RequestInterface $request
*/
public function __construct(\Magento\Framework\App\RequestInterface $request)
{
$this->request = $request;
}

/**
* @param \Magento\Cms\Block\Adminhtml\Wysiwyg\Images\Content $subject
* @param $result
*
* @return string
*/
public function afterGetOnInsertUrl(\Magento\Cms\Block\Adminhtml\Wysiwyg\Images\Content $subject, $result)
{
return $this->request->getParam('on_insert_url') ?: $result;
$onInsertUrl = $this->request->getParam('on_insert_url');

return $onInsertUrl ? urldecode($onInsertUrl) : $result;
}
}

0 comments on commit 93ad05f

Please sign in to comment.