Skip to content
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

Improve opendialogurl configuration to be extensible #27863

Closed
wants to merge 10 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

namespace Magento\Cms\Model\Wysiwyg\Gallery;

use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;

/**
* @inheritdoc
*/
class DefaultConfigProvider implements \Magento\Framework\Data\Wysiwyg\ConfigProviderInterface
{
/**
Expand All @@ -30,26 +35,34 @@ class DefaultConfigProvider implements \Magento\Framework\Data\Wysiwyg\ConfigPro
*/
private $currentTreePath;

/**
* @var OpednDialogUrl
*/
private $openDialogUrl;

/**
* @param \Magento\Backend\Model\UrlInterface $backendUrl
* @param \Magento\Cms\Helper\Wysiwyg\Images $imagesHelper
* @param OpenDialogUrl $openDialogUrl
* @param array $windowSize
* @param string|null $currentTreePath
*/
public function __construct(
\Magento\Backend\Model\UrlInterface $backendUrl,
\Magento\Cms\Helper\Wysiwyg\Images $imagesHelper,
OpenDialogUrl $openDialogUrl,
array $windowSize = [],
$currentTreePath = null
) {
$this->backendUrl = $backendUrl;
$this->imagesHelper = $imagesHelper;
$this->openDialogUrl = $openDialogUrl;
$this->windowSize = $windowSize;
$this->currentTreePath = $currentTreePath;
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Framework\DataObject
{
Expand All @@ -72,7 +85,7 @@ public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Fram
[
'add_images' => true,
'files_browser_window_url' => $this->backendUrl->getUrl(
'cms/wysiwyg_images/index',
$this->openDialogUrl->get(),
$fileBrowserUrlParams
),
'files_browser_window_width' => $this->windowSize['width'],
Expand Down
14 changes: 12 additions & 2 deletions app/code/Magento/Tinymce3/Model/Config/Gallery/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Magento\Tinymce3\Model\Config\Gallery;

use Magento\Ui\Component\Form\Element\DataType\Media\OpenDialogUrl;

/**
* Class Config adds information about required configurations to display media gallery of tinymce3 editor
*
Expand All @@ -19,13 +21,21 @@ class Config implements \Magento\Framework\Data\Wysiwyg\ConfigProviderInterface
*/
private $backendUrl;

/**
* @var OpednDialogUrl
*/
private $openDialogUrl;

/**
* @param \Magento\Backend\Model\UrlInterface $backendUrl
* @param OpenDialogUrl $openDialogUrl
*/
public function __construct(
\Magento\Backend\Model\UrlInterface $backendUrl
\Magento\Backend\Model\UrlInterface $backendUrl,
OpenDialogUrl $openDialogUrl
) {
$this->backendUrl = $backendUrl;
$this->openDialogUrl = $openDialogUrl;
}

/**
Expand All @@ -39,7 +49,7 @@ public function getConfig(\Magento\Framework\DataObject $config) : \Magento\Fram
$config->addData(
[
'add_images' => true,
'files_browser_window_url' => $this->backendUrl->getUrl('cms/wysiwyg_images/index'),
'files_browser_window_url' => $this->backendUrl->getUrl($this->openDialogUrl->get()),
]
);

Expand Down
3 changes: 1 addition & 2 deletions app/code/Magento/Tinymce3/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"magento/module-backend": "*",
"magento/module-ui": "*",
"magento/module-variable": "*",
"magento/module-widget": "*",
"magento/module-cms": "*"
"magento/module-widget": "*"

},
"suggest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,43 @@ class Image extends Media
*/
private $fileSize;

/**
* @var OpednDialogUrl
*/
private $openDialogUrl;

/**
* @param ContextInterface $context
* @param StoreManagerInterface $storeManager
* @param Size $fileSize
* @param OpenDialogUrl $openDialogUrl
* @param UiComponentInterface[] $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
StoreManagerInterface $storeManager,
Size $fileSize,
OpenDialogUrl $openDialogUrl,
array $components = [],
array $data = []
) {
$this->storeManager = $storeManager;
$this->fileSize = $fileSize;
$this->openDialogUrl = $openDialogUrl;
parent::__construct($context, $components, $data);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getComponentName()
{
return static::NAME;
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function prepare()
{
Expand All @@ -75,7 +83,10 @@ public function prepare()
'config' => [
'maxFileSize' => $maxFileSize,
'mediaGallery' => [
'openDialogUrl' => $this->getContext()->getUrl('cms/wysiwyg_images/index', ['_secure' => true]),
'openDialogUrl' => $this->getContext()->getUrl(
$this->openDialogUrl->get(),
['_secure' => true]
),
'openDialogTitle' => $this->getConfiguration()['openDialogTitle'] ?? __('Insert Images...'),
'initialOpenSubpath' => $this->getConfiguration()['initialMediaGalleryOpenSubpath'],
'storeId' => $this->storeManager->getStore()->getId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Ui\Component\Form\Element\DataType\Media;

use Magento\Framework\DataObject;

/**
* Basic configuration for OdenDialogUrl
*/
class OpenDialogUrl
{
private const DEFAULT_OPEN_DIALOG_URL = 'cms/wysiwyg_images/index';

/**
* @var string
*/
private $openDialogUrl;

/**
* @param DataObject $url
*/
public function __construct(DataObject $url = null)
{
$this->openDialogUrl = $url;
}

/**
* Returns open dialog url for media browser
*
* @return string
*/
public function get(): string
{
if ($this->openDialogUrl) {
return $this->openDialogUrl->getUrl();
}
return self::DEFAULT_OPEN_DIALOG_URL;
}
}
3 changes: 1 addition & 2 deletions app/code/Magento/Ui/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"magento/module-backend": "*",
"magento/module-eav": "*",
"magento/module-store": "*",
"magento/module-user": "*",
"magento/module-cms": "*"
"magento/module-user": "*"
},
"suggest": {
"magento/module-config": "*"
Expand Down