ListFileProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 80
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canRender() 0 8 3
A canHandle() 0 4 1
A initialize() 0 7 2
1
<?php
2
declare(strict_types = 1);
3
4
/*
5
 * This file is part of the package typo3/cms-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' => '',
33
        ],
34
        'download' => [
35
            'label' => 'Download',
36
            'iconIdentifier' => 'actions-download',
37
            'callbackAction' => '',
38
        ],
39
        'moveTo' => [
40
            'label' => 'Move to',
41
            'iconIdentifier' => 'actions-move',
42
            'callbackAction' => '',
43
        ],
44
        'copyTo' => [
45
            'label' => 'Copy to',
46
            'iconIdentifier' => 'actions-document-paste-into',
47
            'callbackAction' => '',
48
        ],
49
        'delete' => [
50
            'label' => 'Delete',
51
            'iconIdentifier' => 'actions-delete',
52
            'callbackAction' => '',
53
        ],
54
        'replace' => [
55
            'label' => 'Replace',
56
            'iconIdentifier' => 'actions-replace',
57
            'callbackAction' => '',
58
        ],
59
        'rename' => [
60
            'label' => 'Rename',
61
            'iconIdentifier' => 'actions-rename',
62
            'callbackAction' => '',
63
        ],
64
        'info' => [
65
            'label' => 'Details',
66
            'iconIdentifier' => 'actions-document-info',
67
            'callbackAction' => ''
68
        ],
69
    ];
70
71
    /**
72
     * @var File
73
     */
74
    protected $file;
75
76
    /**
77
     * @return bool
78
     */
79
    public function canHandle(): bool
80
    {
81
        // -drag suffix used to shut down ext:impexp provider that would add import and export items
82
        return $this->table === 'damListFile-drag';
83
    }
84
85
    protected function initialize()
86
    {
87
        parent::initialize();
88
        $resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
89
        $this->file = $resourceFactory->retrieveFileOrFolderObject($this->identifier);
90
        if (!$this->file instanceof File) {
91
            throw new \InvalidArgumentException('uid must be combined identifier of a file');
92
        }
93
    }
94
95
    protected function canRender(string $itemName, string $type): bool
96
    {
97
        if ($itemName === 'preview'
98
            && !GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], strtolower($this->file->getExtension()))
99
        ) {
100
            return false;
101
        }
102
        return true;
103
    }
104
}
105