|
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\File; |
|
15
|
|
|
use TYPO3\CMS\Core\Resource\ResourceFactory; |
|
16
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Click menu on a file or image in list view |
|
20
|
|
|
* 'table' argument must be 'damListFile-drag' |
|
21
|
|
|
* 'uid' argument must be a combinedIdentifier of a file |
|
22
|
|
|
*/ |
|
23
|
|
|
class ListFileProvider extends AbstractProvider |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $itemsConfiguration = [ |
|
29
|
|
|
'preview' => [ |
|
30
|
|
|
'label' => 'Preview', |
|
31
|
|
|
'iconIdentifier' => 'actions-version-workspace-preview', |
|
32
|
|
|
'callbackAction' => 'actionPreview', |
|
33
|
|
|
], |
|
34
|
|
|
'download' => [ |
|
35
|
|
|
'label' => 'Download', |
|
36
|
|
|
'iconIdentifier' => 'actions-download', |
|
37
|
|
|
'callbackAction' => 'actionDownload', |
|
38
|
|
|
], |
|
39
|
|
|
'moveTo' => [ |
|
40
|
|
|
'label' => 'Move to', |
|
41
|
|
|
'iconIdentifier' => 'actions-move', |
|
42
|
|
|
'callbackAction' => 'actionMoveTo', |
|
43
|
|
|
], |
|
44
|
|
|
'copyTo' => [ |
|
45
|
|
|
'label' => 'Copy to', |
|
46
|
|
|
'iconIdentifier' => 'actions-document-paste-into', |
|
47
|
|
|
'callbackAction' => 'actionCopyTo', |
|
48
|
|
|
], |
|
49
|
|
|
'delete' => [ |
|
50
|
|
|
'label' => 'Delete', |
|
51
|
|
|
'iconIdentifier' => 'actions-delete', |
|
52
|
|
|
'callbackAction' => 'actionDelete', |
|
53
|
|
|
], |
|
54
|
|
|
'replace' => [ |
|
55
|
|
|
'label' => 'Replace', |
|
56
|
|
|
'iconIdentifier' => 'actions-replace', |
|
57
|
|
|
'callbackAction' => 'actionReplace', |
|
58
|
|
|
], |
|
59
|
|
|
'rename' => [ |
|
60
|
|
|
'label' => 'Rename', |
|
61
|
|
|
'iconIdentifier' => 'actions-rename', |
|
62
|
|
|
'callbackAction' => 'actionRename', |
|
63
|
|
|
], |
|
64
|
|
|
'info' => [ |
|
65
|
|
|
'label' => 'Details', |
|
66
|
|
|
'iconIdentifier' => 'actions-document-info', |
|
67
|
|
|
'callbackAction' => 'actionInfo' |
|
68
|
|
|
], |
|
69
|
|
|
]; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Registers the additional JavaScript RequireJS callback-module which will allow to display a notification |
|
73
|
|
|
* whenever the user tries to click on the "Hello World" item. |
|
74
|
|
|
* The method is called from AbstractProvider::prepareItems() for each context menu item. |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $itemName |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function getAdditionalAttributes(string $itemName): array |
|
80
|
|
|
{ |
|
81
|
|
|
return [ |
|
82
|
|
|
'data-callback-module' => 'TYPO3/CMS/DigitalAssetManagement/ContextMenuActions', |
|
83
|
|
|
]; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @var File |
|
88
|
|
|
*/ |
|
89
|
|
|
protected $file; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return bool |
|
93
|
|
|
*/ |
|
94
|
|
|
public function canHandle(): bool |
|
95
|
|
|
{ |
|
96
|
|
|
// -drag suffix used to shut down ext:impexp provider that would add import and export items |
|
97
|
|
|
return $this->table === 'damListFile-drag'; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
protected function initialize() |
|
101
|
|
|
{ |
|
102
|
|
|
parent::initialize(); |
|
103
|
|
|
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); |
|
104
|
|
|
$this->file = $resourceFactory->retrieveFileOrFolderObject($this->identifier); |
|
105
|
|
|
if (!$this->file instanceof File) { |
|
106
|
|
|
throw new \InvalidArgumentException('uid must be combined identifier of a file'); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
protected function canRender(string $itemName, string $type): bool |
|
111
|
|
|
{ |
|
112
|
|
|
if ($itemName === 'preview' |
|
113
|
|
|
&& !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($this->file->getExtension())) |
|
114
|
|
|
) { |
|
115
|
|
|
return false; |
|
116
|
|
|
} |
|
117
|
|
|
return true; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|