1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Tika\ContextMenu; |
3
|
|
|
|
4
|
|
|
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider; |
|
|
|
|
5
|
|
|
use TYPO3\CMS\Core\Resource\File; |
6
|
|
|
|
7
|
|
|
class Preview extends AbstractProvider{ |
8
|
|
|
|
9
|
|
|
protected $itemsConfiguration = [ |
10
|
|
|
'tika_preview' => [ |
11
|
|
|
'type' => 'item', |
12
|
|
|
'label' => 'Tika Preview', // you can use "LLL:" syntax here |
13
|
|
|
'iconIdentifier' => 'actions-document-view', |
14
|
|
|
'callbackAction' => 'tikaPreview' |
15
|
|
|
] |
16
|
|
|
]; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Checks if this provider may be called to provide the list of context menu items for given table. |
20
|
|
|
* |
21
|
|
|
* @return bool |
22
|
|
|
*/ |
23
|
|
|
public function canHandle(): bool |
24
|
|
|
{ |
25
|
|
|
if (!$GLOBALS['BE_USER']->isAdmin()) { |
26
|
|
|
return false; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
// Current table is: $this->table |
30
|
|
|
// Current UID is: $this->identifier |
31
|
|
|
if (!$this->table === 'sys_file') { |
|
|
|
|
32
|
|
|
return false; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance(); |
36
|
|
|
$item = $resourceFactory->retrieveFileOrFolderObject($this->identifier); |
37
|
|
|
|
38
|
|
|
// we only handle files, no folders |
39
|
|
|
return ($item instanceof File); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Returns the provider priority which is used for determining the order in which providers are processing items |
44
|
|
|
* to the result array. Highest priority means provider is evaluated first. |
45
|
|
|
* |
46
|
|
|
* This item provider should be called after PageProvider which has priority 100. |
47
|
|
|
* |
48
|
|
|
* BEWARE: Returned priority should logically not clash with another provider. |
49
|
|
|
* Please check @see \TYPO3\CMS\Backend\ContextMenu\ContextMenu::getAvailableProviders() if needed. |
50
|
|
|
* |
51
|
|
|
* @return int |
52
|
|
|
*/ |
53
|
|
|
public function getPriority(): int |
54
|
|
|
{ |
55
|
|
|
return 90; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Registers the additional JavaScript RequireJS callback-module which will allow to display a notification |
60
|
|
|
* whenever the user tries to click on the "Hello World" item. |
61
|
|
|
* The method is called from AbstractProvider::prepareItems() for each context menu item. |
62
|
|
|
* |
63
|
|
|
* @param string $itemName |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
protected function getAdditionalAttributes(string $itemName): array |
67
|
|
|
{ |
68
|
|
|
return ['data-callback-module' => 'TYPO3/CMS/Tika/ContextMenuActions']; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* This method adds custom item to list of items generated by item providers with higher priority value (PageProvider) |
73
|
|
|
* You could also modify existing items here. |
74
|
|
|
* The new item is added after the 'info' item. |
75
|
|
|
* |
76
|
|
|
* @param array $items |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function addItems(array $items): array |
80
|
|
|
{ |
81
|
|
|
|
82
|
|
|
$this->initDisabledItems(); |
83
|
|
|
$localItems = $this->prepareItems($this->itemsConfiguration); |
84
|
|
|
$items = $items + $localItems; |
85
|
|
|
//passes array of items to the next item provider |
86
|
|
|
return $items; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* This method is called for each item this provider adds and checks if given item can be added |
91
|
|
|
* |
92
|
|
|
* @param string $itemName |
93
|
|
|
* @param string $type |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
|
|
protected function canRender(string $itemName, string $type): bool |
97
|
|
|
{ |
98
|
|
|
// checking if item is disabled through TSConfig |
99
|
|
|
if (in_array($itemName, $this->disabledItems, true)) { |
100
|
|
|
return false; |
101
|
|
|
} |
102
|
|
|
switch ($itemName) { |
103
|
|
|
case 'tika_preview': |
104
|
|
|
$canRender = true; |
105
|
|
|
break; |
106
|
|
|
default: |
107
|
|
|
$canRender = false; |
108
|
|
|
} |
109
|
|
|
return $canRender; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths