Skip to content

Commit 989139f

Browse files
committed
Improve button visibility
1 parent dd9bdda commit 989139f

File tree

9 files changed

+91
-27
lines changed

9 files changed

+91
-27
lines changed

app/code/Magento/MediaGalleryUi/Ui/Component/Control/CreateFolder.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ public function __construct(
3636
*/
3737
public function getButtonData()
3838
{
39-
if (!$this->authorization->isAllowed(self::ACL_CREATE_FOLDER)) {
40-
return [];
41-
}
42-
43-
return [
39+
$buttonData = [
4440
'label' => __('Create Folder'),
4541
'on_click' => 'jQuery("#create_folder").trigger("create_folder");',
4642
'class' => 'action-default scalable add media-gallery-actions-buttons',
4743
'sort_order' => 10,
4844
];
45+
46+
if (!$this->authorization->isAllowed(self::ACL_CREATE_FOLDER)) {
47+
$buttonData['disabled'] = 'disabled';
48+
}
49+
50+
return $buttonData;
4951
}
5052
}

app/code/Magento/MediaGalleryUi/Ui/Component/Control/DeleteAssets.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ public function __construct(
3434
/**
3535
* @return array
3636
*/
37-
public function getButtonData()
37+
public function getButtonData(): array
3838
{
39-
if (!$this->authorization->isAllowed(self::ACL_DELETE_ASSETS)) {
40-
return [];
41-
}
42-
43-
return [
39+
$buttonData = [
4440
'label' => __('Delete Images...'),
4541
'on_click' => 'jQuery(window).trigger("massAction.MediaGallery")',
4642
'class' => 'action-default scalable add media-gallery-actions-buttons',
4743
'sort_order' => 50,
4844
];
45+
46+
if (!$this->authorization->isAllowed(self::ACL_DELETE_ASSETS)) {
47+
$buttonData['disabled'] = 'disabled';
48+
}
49+
50+
return $buttonData;
4951
}
5052
}

app/code/Magento/MediaGalleryUi/Ui/Component/Control/DeleteFolder.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@ public function __construct(
3636
*/
3737
public function getButtonData()
3838
{
39-
if (!$this->authorization->isAllowed(self::ACL_DELETE_FOLDER)) {
40-
return [];
41-
}
42-
43-
return [
39+
$buttonData = [
4440
'label' => __('Delete Folder'),
4541
'disabled' => 'disabled',
4642
'on_click' => 'jQuery("#delete_folder").trigger("delete_folder");',
4743
'class' => 'action-default scalable add media-gallery-actions-buttons',
4844
'sort_order' => 30,
4945
];
46+
if (!$this->authorization->isAllowed(self::ACL_DELETE_FOLDER)) {
47+
$buttonData['disabled'] = 'disabled';
48+
}
49+
50+
return $buttonData;
5051
}
5152
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\MediaGalleryUi\Ui\Component\Control;
7+
8+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
9+
use Magento\Framework\AuthorizationInterface;
10+
11+
/**
12+
* Add selected button
13+
*/
14+
class InsertAsstes implements ButtonProviderInterface
15+
{
16+
private const ACL_INSERT_ASSETS = 'Magento_MediaGallery::insert_assets';
17+
18+
/**
19+
* @var AuthorizationInterface
20+
*/
21+
private $authorization;
22+
23+
/**
24+
* Constructor.
25+
*
26+
* @param AuthorizationInterface $authorization
27+
*/
28+
public function __construct(
29+
AuthorizationInterface $authorization
30+
) {
31+
$this->authorization = $authorization;
32+
}
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
public function getButtonData()
38+
{
39+
$buttonData = [
40+
'label' => __('Add Selected'),
41+
'on_click' => 'return false;");',
42+
'class' => 'action-primary no-display media-gallery-add-selected',
43+
'sort_order' => 110,
44+
];
45+
46+
if (!$this->authorization->isAllowed(self::ACL_INSERT_ASSETS)) {
47+
$buttonData['disabled'] = 'disabled';
48+
}
49+
50+
return $buttonData;
51+
}
52+
}

app/code/Magento/MediaGalleryUi/Ui/Component/Control/UploadAssets.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ public function __construct(
3636
*/
3737
public function getButtonData()
3838
{
39-
if (!$this->authorization->isAllowed(self::ACL_UPLOAD_ASSETS)) {
40-
return [];
41-
}
42-
43-
return [
39+
$buttonData = [
4440
'label' => __('Upload Image'),
4541
'disabled' => 'disabled',
4642
'on_click' => 'jQuery("#image-uploader-input").click();',
4743
'class' => 'action-default scalable add media-gallery-actions-buttons',
4844
'sort_order' => 20,
4945
];
46+
47+
if (!$this->authorization->isAllowed(self::ACL_UPLOAD_ASSETS)) {
48+
$buttonData['disabled'] = 'disabled';
49+
}
50+
51+
return $buttonData;
5052
}
5153
}

app/code/Magento/MediaGalleryUi/Ui/Component/DirectoriesTree.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function prepare(): void
5050
array_replace_recursive(
5151
(array) $this->getData('config'),
5252
[
53+
'allowedActions' => [],
5354
'getDirectoryTreeUrl' => $this->url->getUrl("media_gallery/directories/gettree"),
5455
'deleteDirectoryUrl' => $this->url->getUrl("media_gallery/directories/delete"),
5556
'createDirectoryUrl' => $this->url->getUrl("media_gallery/directories/create")

app/code/Magento/MediaGalleryUi/view/adminhtml/ui_component/media_gallery_listing.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
</argument>
1717
<settings>
1818
<buttons>
19-
<button name="add_selected">
20-
<param name="on_click" xsi:type="string">return false;</param>
21-
<param name="sort_order" xsi:type="number">110</param>
22-
<class>action-primary no-display media-gallery-add-selected</class>
23-
<label translate="true">Add Selected</label>
24-
</button>
19+
<button name="add_selected" class="Magento\MediaGalleryUi\Ui\Component\Control\InsertAsstes"/>
2520
<button name="cancel">
2621
<param name="on_click" xsi:type="string">MediabrowserUtility.closeDialog();</param>
2722
<param name="sort_order" xsi:type="number">1</param>

app/code/Magento/MediaGalleryUi/view/adminhtml/web/js/directory/directories.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ define([
179179
* @param {String} folderId
180180
*/
181181
setActive: function (folderId) {
182+
if (!$.inArray('delete_folder', this.allowedActions)) {
183+
return;
184+
}
185+
182186
this.selectedFolder(folderId);
183187
$(this.deleteButtonSelector).removeAttr('disabled').removeClass('disabled');
184188
}

app/code/Magento/MediaGalleryUi/view/adminhtml/web/js/grid/massaction/massactions.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ define([
1616

1717
return Component.extend({
1818
defaults: {
19+
allowedActions: [],
1920
deleteButtonSelector: '#delete_selected_massaction',
2021
deleteImagesSelector: '#delete_massaction',
2122
mediaGalleryImageDetailsName: 'mediaGalleryImageDetails',
@@ -106,6 +107,10 @@ define([
106107
* If images records less than one, disable "delete images" button
107108
*/
108109
checkButtonVisibility: function () {
110+
if (!$.inArray('delete_assets', this.allowedActions)) {
111+
return;
112+
}
113+
109114
if (this.imageItems.length < 1) {
110115
$(this.deleteImagesSelector).addClass('disabled');
111116
} else {

0 commit comments

Comments
 (0)