Completed
Push — master ( 722d75...afea8e )
by Timo
37:55 queued 16:30
created

InitializeConnectionProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 55
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPriority() 0 4 1
A canHandle() 0 14 3
A getAdditionalAttributes() 0 4 1
1
<?php
2
3
namespace ApacheSolrForTypo3\Solr\ContextMenu\ItemProviders;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2017- Timo Hund <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 2 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\RootPageResolver;
29
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32
/**
33
 * Context menu item provider for the solr connection initialization
34
 *
35
 * @author Timo Hund <[email protected]>
36
 */
37
class InitializeConnectionProvider extends AbstractProvider
38
{
39
    /**
40
     * @var array
41
     */
42
    protected $itemsConfiguration = [
43
        'solrconnection' => [
44
            'type' => 'item',
45
            'label' => 'Initialize Solr Connections',
46
            'iconIdentifier' => 'extensions-solr-module-initsolrconnection',
47
            'callbackAction' => 'initializeSolrConnections'
48
        ]
49
    ];
50
51
    /**
52
     * This needs to be lower than priority of the RecordProvider
53
     *
54
     * @return int
55
     */
56
    public function getPriority(): int
57
    {
58
        return 55;
59
    }
60
61
    /**
62
     * Whether this provider can handle given request (usually a check based on table, uid and context)
63
     *
64
     * @return bool
65
     */
66
    public function canHandle(): bool
67
    {
68
        if ($this->table !== 'pages') {
69
            return false;
70
        }
71
72
        if (!$this->backendUser->isAdmin()) {
73
            return false;
74
        }
75
76
        /** @var $rootPageResolver RootPageResolver */
77
        $rootPageResolver = GeneralUtility::makeInstance(RootPageResolver::class);
78
        return $rootPageResolver->getIsRootPageId($this->identifier);
79
    }
80
81
    /**
82
     * Registers custom JS module with item onclick behaviour
83
     *
84
     * @param string $itemName
85
     * @return array
86
     */
87
    protected function getAdditionalAttributes(string $itemName): array
88
    {
89
        return ['data-callback-module' => 'TYPO3/CMS/Solr/ContextMenuActions'];
90
    }
91
}
92