Skip to content

Commit afe499d

Browse files
committed
magento/adobe-stock-integration#1760: Media Gallery page and Category grid page opened successfully if "Enhanced Media Gallery" disabled - redirect to 404 if enhanced media gallery config is disabled.
1 parent 4930963 commit afe499d

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

app/code/Magento/MediaGalleryCatalogUi/Controller/Adminhtml/Category/Index.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
namespace Magento\MediaGalleryCatalogUi\Controller\Adminhtml\Category;
99

1010
use Magento\Backend\App\Action;
11+
use Magento\Backend\App\Action\Context;
1112
use Magento\Backend\Model\View\Result\Page;
13+
use Magento\Backend\Model\View\Result\Forward;
1214
use Magento\Framework\App\Action\HttpGetActionInterface;
1315
use Magento\Framework\Controller\ResultFactory;
1416
use Magento\Framework\Controller\ResultInterface;
17+
use Magento\MediaContentApi\Model\Config;
1518

1619
/**
1720
* Controller serving the media gallery content
@@ -20,13 +23,39 @@ class Index extends Action implements HttpGetActionInterface
2023
{
2124
public const ADMIN_RESOURCE = 'Magento_Cms::media_gallery';
2225

26+
/**
27+
* @var Config
28+
*/
29+
private $config;
30+
31+
/**
32+
* Index constructor.
33+
* @param Context $context
34+
* @param Config $config
35+
*/
36+
public function __construct(
37+
Context $context,
38+
Config $config
39+
) {
40+
parent::__construct($context);
41+
$this->config = $config;
42+
}
43+
2344
/**
2445
* Get the media gallery layout
2546
*
2647
* @return ResultInterface
2748
*/
2849
public function execute(): ResultInterface
2950
{
51+
if (!$this->config->isEnabled()) {
52+
/** @var Forward $resultForward */
53+
$resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
54+
$resultForward->forward('noroute');
55+
56+
return $resultForward;
57+
}
58+
3059
/** @var Page $resultPage */
3160
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
3261
$resultPage->getConfig()->getTitle()->prepend(__('Categories'));

app/code/Magento/MediaGalleryCatalogUi/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"magento/module-backend": "*",
99
"magento/module-catalog": "*",
1010
"magento/module-store": "*",
11-
"magento/module-ui": "*"
11+
"magento/module-ui": "*",
12+
"magento/module-media-content-api": "*"
1213
},
1314
"type": "magento2-module",
1415
"license": [

app/code/Magento/MediaGalleryUi/Controller/Adminhtml/Media/Index.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
use Magento\Framework\App\Action\HttpGetActionInterface;
1313
use Magento\Framework\Controller\ResultFactory;
1414
use Magento\Framework\Controller\ResultInterface;
15+
use Magento\MediaContentApi\Model\Config;
16+
use Magento\Backend\App\Action\Context;
17+
use Magento\Backend\Model\View\Result\Forward;
1518

1619
/**
1720
* Controller serving the media gallery content
@@ -20,13 +23,39 @@ class Index extends Action implements HttpGetActionInterface
2023
{
2124
public const ADMIN_RESOURCE = 'Magento_Cms::media_gallery';
2225

26+
/**
27+
* @var Config
28+
*/
29+
private $config;
30+
31+
/**
32+
* Index constructor.
33+
* @param Context $context
34+
* @param Config $config
35+
*/
36+
public function __construct(
37+
Context $context,
38+
Config $config
39+
) {
40+
parent::__construct($context);
41+
$this->config = $config;
42+
}
43+
2344
/**
2445
* Get the media gallery layout
2546
*
2647
* @return ResultInterface
2748
*/
2849
public function execute(): ResultInterface
2950
{
51+
if (!$this->config->isEnabled()) {
52+
/** @var Forward $resultForward */
53+
$resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
54+
$resultForward->forward('noroute');
55+
56+
return $resultForward;
57+
}
58+
3059
/** @var Page $resultPage */
3160
$resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
3261
$resultPage->setActiveMenu('Magento_MediaGalleryUi::media_gallery')

0 commit comments

Comments
 (0)