‪TYPO3CMS  ‪main
ExtensionComposerStatusController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Http\Message\ResponseInterface;
23 use TYPO3\CMS\Core\Imaging\IconSize;
29 
36 {
37  protected string ‪$returnUrl = '';
38 
39  public function ‪__construct(
40  protected readonly ‪ComposerDeficitDetector $composerDeficitDetector,
41  protected readonly ‪ComposerManifestProposalGenerator $composerManifestProposalGenerator,
42  protected readonly ‪PageRenderer $pageRenderer,
43  protected readonly ‪IconFactory $iconFactory
44  ) {}
45 
46  protected function ‪initializeAction(): void
47  {
48  parent::initializeAction();
49  // The returnUrl, given in the request contains the actual destination, e.g. reports module.
50  // Since we need to forward it in all actions, we define it as class variable here.
51  if ($this->request->hasArgument('returnUrl')) {
52  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(
53  (string)$this->request->getArgument('returnUrl')
54  );
55  }
56  }
57 
58  public function ‪listAction(): ResponseInterface
59  {
60  $extensions = [];
61  // Contains the return link to this action + the initial returnUrl, e.g. reports module
62  $detailLinkReturnUrl = $this->uriBuilder->reset()->uriFor('list', array_filter(['returnUrl' => $this->returnUrl]));
63  foreach ($this->composerDeficitDetector->getExtensionsWithComposerDeficit() as $extensionKey => $extensionInformation) {
64  $extensionInformation['detailLink'] = $this->uriBuilder->reset()->uriFor('detail', [
65  'extensionKey' => $extensionKey,
66  'returnUrl' => $detailLinkReturnUrl,
67  ]);
68  $extensions[$extensionKey] = $extensionInformation;
69  }
70  ksort($extensions);
71  ‪$view = $this->‪initializeModuleTemplate($this->request);
73  ‪$view->assign('extensions', $extensions);
74  return ‪$view->renderResponse('ExtensionComposerStatus/List');
75  }
76 
77  public function ‪detailAction(string $extensionKey): ResponseInterface
78  {
79  if ($extensionKey === '') {
80  return $this->‪redirect('list');
81  }
82  ‪$view = $this->‪initializeModuleTemplate($this->request);
84  $deficit = $this->composerDeficitDetector->checkExtensionComposerDeficit($extensionKey);
85  ‪$view->assignMultiple([
86  'extensionKey' => $extensionKey,
87  'deficit' => $deficit,
88  ]);
90  ‪$view->assign('composerManifestMarkup', $this->‪getComposerManifestMarkup($extensionKey));
91  }
92  return ‪$view->renderResponse('ExtensionComposerStatus/Detail');
93  }
94 
95  protected function ‪getComposerManifestMarkup(string $extensionKey): string
96  {
97  $composerManifest = $this->composerManifestProposalGenerator->getComposerManifestProposal($extensionKey);
98  if ($composerManifest === '') {
99  return '';
100  }
101  $this->pageRenderer->loadJavaScriptModule('@typo3/backend/code-editor/element/code-mirror-element.js');
102  $codeMirrorConfig = [
103  'label' => $extensionKey . ' > composer.json',
104  'panel' => 'bottom',
105  'mode' => GeneralUtility::jsonEncodeForHtmlAttribute(‪JavaScriptModuleInstruction::create('@codemirror/lang-json', 'json')->invoke(), false),
106  'nolazyload' => 'true',
107  'autoheight' => 'true',
108  ];
109  $textareaAttributes = [
110  'rows' => (string)count(explode(LF, $composerManifest)),
111  'class' => 'form-control',
112  ];
113  return '<typo3-t3editor-codemirror ' . GeneralUtility::implodeAttributes($codeMirrorConfig, true) . '>'
114  . '<textarea ' . GeneralUtility::implodeAttributes($textareaAttributes, true) . '>' . htmlspecialchars($composerManifest) . '</textarea>'
115  . '</typo3-t3editor-codemirror>';
116  }
117 
119  {
120  $buttonBar = ‪$view->getDocHeaderComponent()->getButtonBar();
121  if ($this->returnUrl !== '') {
122  // Add "Go back" in case a return url is defined
123  $buttonBar->addButton(
124  $buttonBar
125  ->makeLinkButton()
126  ->setHref($this->returnUrl)
127  ->setClasses('typo3-goBack')
128  ->setTitle($this->‪translate('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
129  ->setShowLabelText(true)
130  ->setIcon($this->iconFactory->getIcon('actions-view-go-back', IconSize::SMALL))
131  );
132  }
133  }
134 }
‪TYPO3\CMS\Extensionmanager\Controller\ExtensionComposerStatusController\initializeAction
‪initializeAction()
Definition: ExtensionComposerStatusController.php:46
‪TYPO3\CMS\Extensionmanager\Service\ComposerManifestProposalGenerator
Definition: ComposerManifestProposalGenerator.php:30
‪TYPO3\CMS\Extensionmanager\Package\ComposerDeficitDetector
Definition: ComposerDeficitDetector.php:27
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$view
‪ViewInterface $view
Definition: ActionController.php:86
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController\translate
‪translate(string $key, ?array $arguments=null)
Definition: AbstractController.php:51
‪TYPO3\CMS\Extensionmanager\Controller\ExtensionComposerStatusController\__construct
‪__construct(protected readonly ComposerDeficitDetector $composerDeficitDetector, protected readonly ComposerManifestProposalGenerator $composerManifestProposalGenerator, protected readonly PageRenderer $pageRenderer, protected readonly IconFactory $iconFactory)
Definition: ExtensionComposerStatusController.php:39
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction\create
‪static create(string $name, string $exportName=null)
Definition: JavaScriptModuleInstruction.php:47
‪TYPO3\CMS\Extensionmanager\Package\ComposerDeficitDetector\EXTENSION_COMPOSER_MANIFEST_VALID
‪const EXTENSION_COMPOSER_MANIFEST_VALID
Definition: ComposerDeficitDetector.php:28
‪TYPO3\CMS\Extensionmanager\Controller\ExtensionComposerStatusController\$returnUrl
‪string $returnUrl
Definition: ExtensionComposerStatusController.php:37
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\Page\JavaScriptModuleInstruction
Definition: JavaScriptModuleInstruction.php:23
‪TYPO3\CMS\Extensionmanager\Controller
Definition: AbstractController.php:18
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Extensionmanager\Controller\ExtensionComposerStatusController
Definition: ExtensionComposerStatusController.php:36
‪TYPO3\CMS\Extensionmanager\Controller\ExtensionComposerStatusController\listAction
‪listAction()
Definition: ExtensionComposerStatusController.php:58
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController\initializeModuleTemplate
‪initializeModuleTemplate(RequestInterface $request)
Definition: AbstractController.php:76
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:44
‪TYPO3\CMS\Extensionmanager\Controller\ExtensionComposerStatusController\getComposerManifestMarkup
‪getComposerManifestMarkup(string $extensionKey)
Definition: ExtensionComposerStatusController.php:95
‪TYPO3\CMS\Extensionmanager\Controller\ExtensionComposerStatusController\registerDocHeaderButtons
‪registerDocHeaderButtons(ModuleTemplate $view)
Definition: ExtensionComposerStatusController.php:118
‪TYPO3\CMS\Extensionmanager\Controller\ExtensionComposerStatusController\detailAction
‪detailAction(string $extensionKey)
Definition: ExtensionComposerStatusController.php:77
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController
Definition: AbstractController.php:32
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\redirect
‪redirect(?string $actionName, ?string $controllerName=null, ?string $extensionName=null, ?array $arguments=null, ?int $pageUid=null, $_=null, int $statusCode=303)
Definition: ActionController.php:688
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52