1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApacheSolrForTypo3\Tika\ContextMenu; |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
* This file is part of the TYPO3 CMS project. |
9
|
|
|
* |
10
|
|
|
* It is free software; you can redistribute it and/or modify it under |
11
|
|
|
* the terms of the GNU General Public License, either version 2 |
12
|
|
|
* of the License, or any later version. |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, please read the |
15
|
|
|
* LICENSE.txt file that was distributed with this source code. |
16
|
|
|
* |
17
|
|
|
* The TYPO3 project - inspiring people to share! |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider; |
21
|
|
|
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException; |
22
|
|
|
use TYPO3\CMS\Core\Resource\File; |
23
|
|
|
use TYPO3\CMS\Core\Resource\ResourceFactory; |
24
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
25
|
|
|
|
26
|
|
|
class Preview extends AbstractProvider |
27
|
|
|
{ |
28
|
|
|
protected $itemsConfiguration = [ |
29
|
|
|
'tika_preview' => [ |
30
|
|
|
'type' => 'item', |
31
|
|
|
'label' => 'Tika Preview', // you can use "LLL:" syntax here |
32
|
|
|
'iconIdentifier' => 'actions-document-view', |
33
|
|
|
'callbackAction' => 'tikaPreview', |
34
|
|
|
], |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Checks if this provider may be called to provide the list of context menu items for given table. |
39
|
|
|
* |
40
|
|
|
* @return bool |
41
|
|
|
* @throws ResourceDoesNotExistException |
42
|
|
|
*/ |
43
|
|
|
public function canHandle(): bool |
44
|
|
|
{ |
45
|
|
|
if (empty($GLOBALS['BE_USER']) || !$GLOBALS['BE_USER']->isAdmin()) { |
46
|
|
|
return false; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// Current table is: $this->table |
50
|
|
|
// Current UID is: $this->identifier |
51
|
|
|
if ($this->table !== 'sys_file') { |
52
|
|
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class); |
56
|
|
|
$item = $resourceFactory->retrieveFileOrFolderObject($this->identifier); |
57
|
|
|
|
58
|
|
|
// we only handle files, no folders |
59
|
|
|
return $item instanceof File; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns the provider priority which is used for determining the order in which providers are processing items |
64
|
|
|
* to the result array. Highest priority means provider is evaluated first. |
65
|
|
|
* |
66
|
|
|
* This item provider should be called after PageProvider which has priority 100. |
67
|
|
|
* |
68
|
|
|
* BEWARE: Returned priority should logically not clash with another provider. |
69
|
|
|
* Please check @see \TYPO3\CMS\Backend\ContextMenu\ContextMenu::getAvailableProviders() if needed. |
70
|
|
|
* |
71
|
|
|
* @return int |
72
|
|
|
*/ |
73
|
|
|
public function getPriority(): int |
74
|
|
|
{ |
75
|
|
|
return 90; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Registers the additional JavaScript RequireJS callback-module which will allow to display a notification |
80
|
|
|
* whenever the user tries to click on the "Hello World" item. |
81
|
|
|
* The method is called from AbstractProvider::prepareItems() for each context menu item. |
82
|
|
|
* |
83
|
|
|
* @param string $itemName |
84
|
|
|
* @return array |
85
|
|
|
*/ |
86
|
|
|
protected function getAdditionalAttributes(string $itemName): array |
87
|
|
|
{ |
88
|
|
|
return ['data-callback-module' => 'TYPO3/CMS/Tika/ContextMenuActions']; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* This method adds custom item to list of items generated by item providers with higher priority value (PageProvider) |
93
|
|
|
* You could also modify existing items here. |
94
|
|
|
* The new item is added after the 'info' item. |
95
|
|
|
* |
96
|
|
|
* @param array $items |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function addItems(array $items): array |
100
|
|
|
{ |
101
|
|
|
$this->initDisabledItems(); |
102
|
|
|
$localItems = $this->prepareItems($this->itemsConfiguration); |
103
|
|
|
//passes array of items to the next item provider |
104
|
|
|
return $items + $localItems; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* This method is called for each item this provider adds and checks if given item can be added |
109
|
|
|
* |
110
|
|
|
* @param string $itemName |
111
|
|
|
* @param string $type |
112
|
|
|
* @return bool |
113
|
|
|
*/ |
114
|
|
|
protected function canRender(string $itemName, string $type): bool |
115
|
|
|
{ |
116
|
|
|
// checking if item is disabled through TSConfig |
117
|
|
|
if (in_array($itemName, $this->disabledItems, true)) { |
118
|
|
|
return false; |
119
|
|
|
} |
120
|
|
|
switch ($itemName) { |
121
|
|
|
case 'tika_preview': |
122
|
|
|
$canRender = true; |
123
|
|
|
break; |
124
|
|
|
default: |
125
|
|
|
$canRender = false; |
126
|
|
|
} |
127
|
|
|
return $canRender; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|