Completed
Branch master (b7ffcb)
by Tomas Norre
17:57
created

CrawlerClickMenu::main()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 33
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 21
nc 3
nop 4
dl 0
loc 33
rs 8.8571
c 0
b 0
f 0
1
<?php
2
namespace AOE\Crawler\ClickMenu;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2017 AOE GmbH <[email protected]>
8
 *
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 3 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 TYPO3\CMS\Backend\ClickMenu\ClickMenu;
29
use TYPO3\CMS\Backend\Utility\BackendUtility;
30
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
31
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
32
33
/**
34
 * Class CrawlerClickMenu
35
 *
36
 * @package AOE\Crawler\ClickMenu
37
 */
38
class CrawlerClickMenu
39
{
40
    /**
41
     * Main function
42
     *
43
     * @param ClickMenu $backRef reference parent object
44
     * @param array $menuItems
45
     * @param string $tableName
46
     * @param integer $uid
47
     *
48
     * @return array
49
     */
50
    public function main(ClickMenu $backRef, array $menuItems, $tableName, $uid)
51
    {
52
        if ('tx_crawler_configuration' !== $tableName) {
53
            return $menuItems;
54
        }
55
56
        $crawlerConfiguration = BackendUtility::getRecord(
57
            $tableName,
58
            $uid,
59
            'pid, name'
60
        );
61
62
        if (!$crawlerConfiguration) {
63
            return $menuItems;
64
        }
65
66
        $additionalParameters = [];
67
        $additionalParameters[] = 'SET[function]=tx_crawler_modfunc1';
68
        $additionalParameters[] = 'SET[crawlaction]=start';
69
        $additionalParameters[] = 'configurationSelection[]=' . $crawlerConfiguration['name'];
70
71
        $additionalMenuItems = [];
72
        $additionalMenuItems[] = $backRef->linkItem(
73
            LocalizationUtility::translate(
74
                'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:contextMenu.label',
75
                'crawler'
76
            ),
77
            $this->getContextMenuIcon(),
78
            'top.goToModule(\'web_info\', 1, \'&' . implode('&', $additionalParameters) . '\'); return hideCM();'
79
        );
80
81
        return array_merge($menuItems, $additionalMenuItems);
82
    }
83
84
    /**
85
     * Helper function to render the context menu icon
86
     *
87
     * @return string
88
     */
89
    private function getContextMenuIcon()
90
    {
91
        $icon = sprintf(
92
            '<img src="%s" border="0" align="top" alt="" />',
93
            ExtensionManagementUtility::extRelPath('crawler') . 'Resources/Private/Icons/icon_tx_crawler_configuration.gif'
94
        );
95
96
        return $icon;
97
    }
98
}
99