UpdateScriptViewHelper.php 2.57 KB
Newer Older
1
<?php
2

3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
7
8
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
9
 *
10
11
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
14
 * The TYPO3 project - inspiring people to share!
 */
15

16
17
namespace TYPO3\CMS\Extensionmanager\ViewHelpers;

18
19
20
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
22
23
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Extensionmanager\Utility\UpdateScriptUtility;
24
use TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper;
25
26

/**
27
 * ViewHelper for update script link
28
 * @internal
29
 */
30
class UpdateScriptViewHelper extends ActionViewHelper
31
{
32
33
34
35
36
37
38
39
40
    /**
     * initialize arguments
     */
    public function initializeArguments()
    {
        parent::initializeArguments();
        $this->registerArgument('extensionKey', 'string', 'Extension key', true);
    }

41
42
43
44
45
    /**
     * Renders a link to the update script screen if the extension has one
     *
     * @return string The rendered a tag
     */
46
    public function render()
47
    {
48
        $extensionKey = $this->arguments['extensionKey'];
49

50
        // If the "class.ext_update.php" file exists, build link to the update script screen
51
        $updateScriptUtility = GeneralUtility::makeInstance(UpdateScriptUtility::class);
52
53
        $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
        if ($updateScriptUtility->checkUpdateScriptExists($extensionKey)) {
54
            /** @var UriBuilder $uriBuilder */
55
56
            $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
            $uriBuilder->setRequest($this->renderingContext->getRequest());
57
58
59
            $action = 'show';
            $uri = $uriBuilder->reset()->uriFor(
                $action,
60
                ['extensionKey' => $extensionKey],
61
62
63
                'UpdateScript'
            );
            $this->tag->addAttribute('href', $uri);
64
            $this->tag->addAttribute('title', LocalizationUtility::translate('extensionList.update.script', 'extensionmanager'));
65
            $this->tag->setContent($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render());
66
67
68
69
70
71
            $tag = $this->tag->render();
        } else {
            return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
        }
        return $tag;
    }
72
}