Completed
Push — typo3v9 ( 400b41...f5e04d )
by Tomas Norre
05:40
created

ItemProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 63
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A canHandle() 0 4 1
A getPriority() 0 4 1
A addItems() 0 6 1
A getAdditionalAttributes() 0 12 1
1
<?php
2
declare(strict_types = 1);
3
namespace AOE\Crawler\ContextMenu;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2017 AOE GmbH <[email protected]>
9
 *
10
 *  All rights reserved
11
 *
12
 *  This script is part of the TYPO3 project. The TYPO3 project is
13
 *  free software; you can redistribute it and/or modify
14
 *  it under the terms of the GNU General Public License as published by
15
 *  the Free Software Foundation; either version 3 of the License, or
16
 *  (at your option) any later version.
17
 *
18
 *  The GNU General Public License can be found at
19
 *  http://www.gnu.org/copyleft/gpl.html.
20
 *
21
 *  This script is distributed in the hope that it will be useful,
22
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 *  GNU General Public License for more details.
25
 *
26
 *  This copyright notice MUST APPEAR in all copies of the script!
27
 ***************************************************************/
28
29
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider;
30
use TYPO3\CMS\Backend\Utility\BackendUtility;
31
use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33
/**
34
 * Provides a ContextMenu item
35
 */
36
class ItemProvider extends AbstractProvider
37
{
38
    /**
39
     * @var array
40
     */
41
    protected $itemsConfiguration = [
42
        'crawler' => [
43
            'type' => 'item',
44
            'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:contextMenu.label',
45
            'iconIdentifier' => 'tx-crawler',
46
            'callbackAction' => 'crawler'
47
        ]
48
    ];
49
50
    /**
51
     * Item is added only for crawler configurations
52
     *
53
     * @return bool
54
     */
55
    public function canHandle(): bool
56
    {
57
        return $this->table === 'tx_crawler_configuration';
58
    }
59
60
    /**
61
     * This needs to be lower than priority of the RecordProvider
62
     *
63
     * @return int
64
     */
65
    public function getPriority(): int
66
    {
67
        return 50;
68
    }
69
70
    /**
71
     * Adds the crawler info
72
     *
73
     * @param array $items
74
     * @return array
75
     */
76
    public function addItems(array $items): array
77
    {
78
        $localItems = $this->prepareItems($this->itemsConfiguration);
79
        $items += $localItems;
80
        return $items;
81
    }
82
83
    /**
84
     * @inheritDoc
85
     */
86
    protected function getAdditionalAttributes(string $itemName): array
87
    {
88
        $crawlerConfiguration = BackendUtility::getRecordWSOL($this->table, $this->identifier);
89
90
        $additionalParameters = [];
91
        $additionalParameters[] = 'SET[function]=AOE\Crawler\Backend\BackendModule';
92
        $additionalParameters[] = 'SET[crawlaction]=start';
93
        $additionalParameters[] = 'configurationSelection[]=' . $crawlerConfiguration['name'];
94
        return [
95
            'onclick' => 'top.goToModule(\'web_info\', 1, ' . GeneralUtility::quoteJSvalue('&' . implode('&', $additionalParameters)) . ');'
96
        ];
97
    }
98
}
99