[!!!][TASK] Remove CMS base ViewHelper classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / ViewHelpers / UpdateScriptViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\ViewHelpers;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Imaging\Icon;
18 use TYPO3\CMS\Core\Imaging\IconFactory;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * View helper for update script link
23 * @internal
24 */
25 class UpdateScriptViewHelper extends Link\ActionViewHelper
26 {
27 /**
28 * initialize arguments
29 */
30 public function initializeArguments()
31 {
32 parent::initializeArguments();
33 $this->registerArgument('extensionKey', 'string', 'Extension key', true);
34 }
35
36 /**
37 * Renders a link to the update script screen if the extension has one
38 *
39 * @return string The rendered a tag
40 */
41 public function render()
42 {
43 $extensionKey = $this->arguments['extensionKey'];
44 $tag = '';
45
46 // If the "class.ext_update.php" file exists, build link to the update script screen
47 /** @var $updateScriptUtility \TYPO3\CMS\Extensionmanager\Utility\UpdateScriptUtility */
48 $updateScriptUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\UpdateScriptUtility::class);
49 /** @var IconFactory $iconFactory */
50 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
51 if ($updateScriptUtility->checkUpdateScriptExists($extensionKey)) {
52 $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
53 $action = 'show';
54 $uri = $uriBuilder->reset()->uriFor(
55 $action,
56 ['extensionKey' => $extensionKey],
57 'UpdateScript'
58 );
59 $this->tag->addAttribute('href', $uri);
60 $this->tag->addAttribute('title', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('extensionList.update.script', 'extensionmanager'));
61 $this->tag->setContent($iconFactory->getIcon('extensions-extensionmanager-update-script', Icon::SIZE_SMALL)->render());
62 $tag = $this->tag->render();
63 } else {
64 return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
65 }
66 return $tag;
67 }
68 }