[!!!][TASK] Remove CMS base ViewHelper classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / ViewHelpers / ConfigureExtensionViewHelper.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 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
21
22 /**
23 * View helper for configure extension link
24 * @internal
25 */
26 class ConfigureExtensionViewHelper extends Link\ActionViewHelper
27 {
28 /**
29 * Initialize arguments
30 */
31 public function initializeArguments()
32 {
33 parent::initializeArguments();
34 $this->registerArgument('extension', 'array', 'Extension configuration array with extension information', true);
35 $this->registerArgument('forceConfiguration', 'bool', 'If TRUE the content is only returned if a link could be generated', false, true);
36 $this->registerArgument('showDescription', 'bool', 'If TRUE the extension description is also shown in the title attribute', false, false);
37 }
38
39 /**
40 * Renders a configure extension link if the extension has configuration options
41 *
42 * @return string the rendered tag or child nodes content
43 */
44 public function render()
45 {
46 $extension = $this->arguments['extension'];
47 $forceConfiguration = $this->arguments['forceConfiguration'];
48 $showDescription = $this->arguments['showDescription'];
49
50 $content = (string)$this->renderChildren();
51 if ($extension['installed'] && file_exists(PATH_site . $extension['siteRelPath'] . 'ext_conf_template.txt')) {
52 $uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
53 $action = 'showConfigurationForm';
54 $uri = $uriBuilder->reset()->uriFor(
55 $action,
56 ['extension' => ['key' => $extension['key']]],
57 'Configuration'
58 );
59 if ($showDescription) {
60 $title = $extension['description'] . PHP_EOL .
61 LocalizationUtility::translate('extensionList.clickToConfigure', 'extensionmanager');
62 } else {
63 $title = LocalizationUtility::translate('extensionList.configure', 'extensionmanager');
64 }
65 $this->tag->addAttribute('href', $uri);
66 $this->tag->addAttribute('title', $title);
67 $this->tag->setContent($content);
68 $content = $this->tag->render();
69 } elseif ($forceConfiguration) {
70 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
71 $content = '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
72 } else {
73 $content = '<span title="' . htmlspecialchars($extension['description']) . '">' . $content . '</span>';
74 }
75
76 return $content;
77 }
78 }