Passed
Push — task/context-menu ( 14c51a...802bb3 )
by Frank
03:37 queued 01:20
created

getAdditionalAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types = 1);
3
4
/*
5
 * This file is part of the package lns/digital-asset-management.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE file that was distributed with this source code.
9
 */
10
11
namespace TYPO3\CMS\DigitalAssetManagement\ContextMenu\ItemProviders;
12
13
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider;
14
use TYPO3\CMS\Core\Resource\FolderInterface;
15
use TYPO3\CMS\Core\Resource\ResourceFactory;
16
use TYPO3\CMS\Core\Resource\ResourceStorage;
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19
/**
20
 * Click menu on a storage or file mount
21
 * 'table' argument must be 'damStoragesAndMounts-drag'
22
 * 'uid' argument must be either the uid of a sys_file_storage, or a combinedIdentifier for a file mount
23
 */
24
class StoragesAndMountsProvider extends AbstractProvider
25
{
26
    /**
27
     * @var array
28
     */
29
    protected $itemsConfiguration = [
30
        'newFile' => [
31
            'label' => 'New File',
32
            'iconIdentifier' => 'actions-page-new',
33
            'callbackAction' => 'actionNewFile',
34
        ],
35
        'newFolder' => [
36
            'label' => 'New Folder',
37
            'iconIdentifier' => 'actions-folder',
38
            'callbackAction' => 'actionNewFolder',
39
        ],
40
        'upload' => [
41
            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:cm.upload',
42
            'iconIdentifier' => 'actions-edit-upload',
43
            'callbackAction' => 'actionUpload'
44
        ],
45
        'editStorage' => [
46
            'label' => 'Edit Storage',
47
            'iconIdentifier' => 'actions-open',
48
            'callbackAction' => 'actionEditStorage'
49
        ],
50
        'info' => [
51
            'label' => 'Details',
52
            'iconIdentifier' => 'actions-document-info',
53
            'callbackAction' => 'actionInfo'
54
        ],
55
    ];
56
57
    /**
58
     * Registers the additional JavaScript RequireJS callback-module which will allow to display a notification
59
     * whenever the user tries to click on the "Hello World" item.
60
     * The method is called from AbstractProvider::prepareItems() for each context menu item.
61
     *
62
     * @param string $itemName
63
     * @return array
64
     */
65
    protected function getAdditionalAttributes(string $itemName): array
66
    {
67
        return [
68
            'data-callback-module' => 'TYPO3/CMS/DigitalAssetManagement/ContextMenuActions',
69
        ];
70
    }
71
72
    /**
73
     * @var ResourceStorage
74
     */
75
    protected $storage;
76
77
    /**
78
     * @var FolderInterface
79
     */
80
    protected $mount;
81
82
    /**
83
     * @return bool
84
     */
85
    public function canHandle(): bool
86
    {
87
        // -drag suffix used to shut down ext:impexp provider that would add import and export items
88
        return $this->table === 'damStoragesAndMounts-drag';
89
    }
90
91
    protected function initialize()
92
    {
93
        parent::initialize();
94
        $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
95
        if (is_numeric($this->identifier)) {
96
            $this->storage = $resourceFactory->getStorageObject($this->identifier);
97
        } else {
98
            $this->mount = $resourceFactory->retrieveFileOrFolderObject($this->identifier);
99
            if (!$this->mount instanceof FolderInterface) {
100
                throw new \InvalidArgumentException('uid must be either the uid of a storage, or a file mount folder');
101
            }
102
        }
103
    }
104
105
    protected function canRender(string $itemName, string $type): bool
106
    {
107
        if ($itemName === 'editStorage' && !$this->storage instanceof ResourceStorage) {
0 ignored issues
show
introduced by
$this->storage is always a sub-type of TYPO3\CMS\Core\Resource\ResourceStorage.
Loading history...
108
            return false;
109
        }
110
        return true;
111
    }
112
}
113