‪TYPO3CMS  ‪main
ListController.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;
26 use TYPO3\CMS\Core\Imaging\IconSize;
41 
49 {
50  public function ‪__construct(
51  protected readonly ‪PageRenderer $pageRenderer,
52  protected readonly ‪ExtensionRepository $extensionRepository,
53  protected readonly ‪ListUtility $listUtility,
54  protected readonly ‪DependencyUtility $dependencyUtility,
55  protected readonly ‪IconFactory $iconFactory,
56  protected readonly ‪RemoteRegistry $remoteRegistry,
57  protected readonly ‪ExtensionConfiguration $extensionConfiguration,
58  ) {}
59 
63  protected function ‪initializeAction(): void
64  {
65  $this->pageRenderer->addInlineLanguageLabelFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
66  $this->settings['offlineMode'] = (bool)$this->extensionConfiguration->get('extensionmanager', 'offlineMode');
67  }
68 
72  protected function ‪indexAction(): ResponseInterface
73  {
74  $moduleData = $this->request->getAttribute('moduleData');
75  if ($this->request->hasArgument('filter')
76  && is_string($this->request->getArgument('filter'))
77  ) {
78  $filter = $this->request->getArgument('filter');
79  $moduleData->set('filter', $filter);
80  $this->‪getBackendUserAuthentication()->pushModuleData($moduleData->getModuleIdentifier(), $moduleData->toArray());
81  } else {
82  $filter = (string)$moduleData->get('filter');
83  }
85  $isComposerMode = ‪Environment::isComposerMode();
86  $availableAndInstalledExtensions = $this->‪enrichExtensionsWithViewInformation(
87  $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation($filter),
88  $isComposerMode
89  );
90  ksort($availableAndInstalledExtensions);
91  ‪$view = $this->‪initializeModuleTemplate($this->request);
93  ‪$view->assignMultiple([
94  'extensions' => $availableAndInstalledExtensions,
95  'isComposerMode' => $isComposerMode,
96  'typeFilter' => $filter ?: 'All',
97  // Sort extension by update state. This is only automatically set for non-composer
98  // mode and only takes effect if at least one extension can be updated.
99  'sortByUpdate' => $this->‪extensionsWithUpdate($availableAndInstalledExtensions) !== [] && !$isComposerMode,
100  ]);
102  return ‪$view->renderResponse('List/Index');
103  }
104 
108  protected function ‪unresolvedDependenciesAction(string $extensionKey, array $returnAction): ResponseInterface
109  {
110  $availableExtensions = $this->listUtility->getAvailableExtensions();
111  if (isset($availableExtensions[$extensionKey])) {
112  $extensionArray = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation(
113  [
114  $extensionKey => $availableExtensions[$extensionKey],
115  ]
116  );
117  $extension = ‪Extension::createFromExtensionArray($extensionArray[$extensionKey]);
118  } else {
119  throw new ‪ExtensionManagerException('Extension ' . $extensionKey . ' is not available', 1402421007);
120  }
121  $this->dependencyUtility->checkDependencies($extension);
122  ‪$view = $this->‪initializeModuleTemplate($this->request);
123  ‪$view->assignMultiple([
124  'extension' => $extension,
125  'returnAction' => $returnAction,
126  'unresolvedDependencies' => $this->dependencyUtility->getDependencyErrors(),
127  ]);
128  return ‪$view->renderResponse('List/UnresolvedDependencies');
129  }
130 
134  protected function ‪terAction(string $search = '', int $currentPage = 1): ResponseInterface
135  {
137  $search = trim($search);
138  if (!empty($search)) {
139  $extensions = $this->extensionRepository->findByTitleOrAuthorNameOrExtensionKey($search);
140  $paginator = new ‪ArrayPaginator($extensions, $currentPage);
141  $tableId = 'terSearchTable';
142  } else {
144  $extensions = $this->extensionRepository->findAll();
145  $paginator = new ‪QueryResultPaginator($extensions, $currentPage);
146  $tableId = 'terTable';
147  }
148  $pagination = new ‪SimplePagination($paginator);
149  $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensions($this->listUtility->getAvailableExtensions());
150  ‪$view = $this->‪initializeModuleTemplate($this->request);
152  ‪$view->assignMultiple([
153  'extensions' => $extensions,
154  'paginator' => $paginator,
155  'pagination' => $pagination,
156  'search' => $search,
157  'availableAndInstalled' => $availableAndInstalledExtensions,
158  'actionName' => 'ter',
159  'tableId' => $tableId,
160  ]);
161  return ‪$view->renderResponse('List/Ter');
162  }
163 
167  protected function ‪distributionsAction(bool $showUnsuitableDistributions = false): ResponseInterface
168  {
169  $this->pageRenderer->loadJavaScriptModule('@typo3/extensionmanager/distribution-image.js');
171  $importExportInstalled = ‪ExtensionManagementUtility::isLoaded('impexp');
172  ‪$view = $this->‪initializeModuleTemplate($this->request);
173  if ($importExportInstalled) {
174  try {
175  foreach ($this->remoteRegistry->getListableRemotes() as $remote) {
176  $remote->getAvailablePackages();
177  }
178  } catch (‪ExtensionManagerException $e) {
179  $this->‪addFlashMessage($e->getMessage(), $e->getCode(), ContextualFeedbackSeverity::ERROR);
180  }
181  $officialDistributions = $this->extensionRepository->findAllOfficialDistributions($showUnsuitableDistributions);
182  $communityDistributions = $this->extensionRepository->findAllCommunityDistributions($showUnsuitableDistributions);
183  ‪$view->assign('officialDistributions', $officialDistributions);
184  ‪$view->assign('communityDistributions', $communityDistributions);
185  }
186  ‪$view->assign('enableDistributionsView', $importExportInstalled);
187  ‪$view->assign('showUnsuitableDistributions', $showUnsuitableDistributions);
188  return ‪$view->renderResponse('List/Distributions');
189  }
190 
194  protected function ‪showAllVersionsAction(string $extensionKey): ResponseInterface
195  {
196  $currentVersion = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extensionKey);
197  $extensions = $this->extensionRepository->findByExtensionKeyOrderedByVersion($extensionKey);
198  ‪$view = $this->‪initializeModuleTemplate($this->request);
200  ‪$view->assignMultiple([
201  'extensionKey' => $extensionKey,
202  'currentVersion' => $currentVersion,
203  'extensions' => $extensions,
204  ]);
205  return ‪$view->renderResponse('List/ShowAllVersions');
206  }
207 
212  {
214  return ‪$view;
215  }
216  $buttonBar = ‪$view->getDocHeaderComponent()->getButtonBar();
217  if ($this->actionMethodName === 'showAllVersionsAction') {
218  $action = $this->request->hasArgument('returnTo') ? $this->request->getArgument('returnTo') : 'ter';
219  $uri = $this->uriBuilder->reset()->uriFor(in_array($action, ['index', 'ter'], true) ? $action : 'ter', [], 'List');
220  $title = $this->‪translate('extConfTemplate.backToList');
221  $icon = $this->iconFactory->getIcon('actions-view-go-back', IconSize::SMALL);
222  $classes = '';
223  } else {
224  $uri = $this->uriBuilder->reset()->uriFor('form', [], 'UploadExtensionFile');
225  $title = $this->‪translate('extensionList.uploadExtension');
226  $icon = $this->iconFactory->getIcon('actions-edit-upload', IconSize::SMALL);
227  $classes = 't3js-upload';
228  }
229  $button = $buttonBar->makeLinkButton()
230  ->setHref($uri)
231  ->setTitle($title)
232  ->setShowLabelText(true)
233  ->setClasses($classes)
234  ->setIcon($icon);
235  $buttonBar->addButton($button);
236  return ‪$view;
237  }
238 
242  protected function ‪addComposerModeNotification(): void
243  {
245  $this->‪addFlashMessage(
247  'composerStrictMode.message',
248  'extensionmanager'
249  ) ?? '',
251  'composerMode.title',
252  'extensionmanager'
253  ) ?? '',
254  ContextualFeedbackSeverity::INFO
255  );
256  }
257  }
258 
259  protected function ‪enrichExtensionsWithViewInformation(array $availableAndInstalledExtensions, bool $isComposerMode): array
260  {
261  $isOfflineMode = (bool)($this->settings['offlineMode'] ?? false);
262  foreach ($availableAndInstalledExtensions as &$extension) {
263  $extension['updateIsBlocked'] = $isComposerMode || $isOfflineMode || ($extension['state'] ?? '') === 'excludeFromUpdates';
264  $extension['sortUpdate'] = 2;
265  if ($extension['updateAvailable'] ?? false) {
266  $extension['sortUpdate'] = (int)$extension['updateIsBlocked'];
267  }
268  }
269  return $availableAndInstalledExtensions;
270  }
271 
272  protected function ‪extensionsWithUpdate(array $availableAndInstalledExtensions): array
273  {
274  return array_filter($availableAndInstalledExtensions, static function ($extension) {
275  return $extension['updateAvailable'] ?? false;
276  });
277  }
278 
280  {
281  return ‪$GLOBALS['BE_USER'];
282  }
283 }
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\addFlashMessage
‪addFlashMessage(string $messageBody, string $messageTitle='', ContextualFeedbackSeverity $severity=ContextualFeedbackSeverity::OK, bool $storeInSession=true)
Definition: ActionController.php:637
‪TYPO3\CMS\Extensionmanager\Controller\ListController\indexAction
‪indexAction()
Definition: ListController.php:72
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:35
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:30
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:47
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$view
‪ViewInterface $view
Definition: ActionController.php:86
‪TYPO3\CMS\Extensionmanager\Controller\ListController\addComposerModeNotification
‪addComposerModeNotification()
Definition: ListController.php:242
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController\translate
‪translate(string $key, ?array $arguments=null)
Definition: AbstractController.php:51
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static isComposerMode()
Definition: Environment.php:137
‪TYPO3\CMS\Extbase\Pagination\QueryResultPaginator
Definition: QueryResultPaginator.php:24
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Extensionmanager\Controller
Definition: AbstractController.php:18
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:41
‪TYPO3\CMS\Extensionmanager\Controller\ListController\initializeAction
‪initializeAction()
Definition: ListController.php:63
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Core\Pagination\SimplePagination
Definition: SimplePagination.php:21
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static isLoaded(string $key)
Definition: ExtensionManagementUtility.php:55
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\createFromExtensionArray
‪static createFromExtensionArray(array $extensionArray)
Definition: Extension.php:418
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:32
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Extensionmanager\Controller\ListController\__construct
‪__construct(protected readonly PageRenderer $pageRenderer, protected readonly ExtensionRepository $extensionRepository, protected readonly ListUtility $listUtility, protected readonly DependencyUtility $dependencyUtility, protected readonly IconFactory $iconFactory, protected readonly RemoteRegistry $remoteRegistry, protected readonly ExtensionConfiguration $extensionConfiguration,)
Definition: ListController.php:50
‪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\ListController\enrichExtensionsWithViewInformation
‪enrichExtensionsWithViewInformation(array $availableAndInstalledExtensions, bool $isComposerMode)
Definition: ListController.php:259
‪TYPO3\CMS\Extensionmanager\Utility\DependencyUtility
Definition: DependencyUtility.php:37
‪TYPO3\CMS\Extensionmanager\Controller\ListController\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: ListController.php:279
‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
Definition: ExtensionRepository.php:37
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, Locale|string $languageKey=null)
Definition: LocalizationUtility.php:47
‪TYPO3\CMS\Extensionmanager\Controller\ListController\distributionsAction
‪distributionsAction(bool $showUnsuitableDistributions=false)
Definition: ListController.php:167
‪TYPO3\CMS\Extensionmanager\Controller\ListController\terAction
‪terAction(string $search='', int $currentPage=1)
Definition: ListController.php:134
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:25
‪TYPO3\CMS\Extbase\Persistence\QueryResultInterface
Definition: QueryResultInterface.php:26
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:61
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController
Definition: AbstractController.php:32
‪TYPO3\CMS\Extensionmanager\Controller\ListController\extensionsWithUpdate
‪extensionsWithUpdate(array $availableAndInstalledExtensions)
Definition: ListController.php:272
‪TYPO3\CMS\Extensionmanager\Controller\ListController\registerDocHeaderButtons
‪registerDocHeaderButtons(ModuleTemplate $view)
Definition: ListController.php:211
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController\handleTriggerArguments
‪handleTriggerArguments(ModuleTemplate $view)
Definition: AbstractController.php:61
‪TYPO3\CMS\Core\Pagination\ArrayPaginator
Definition: ArrayPaginator.php:21
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Extensionmanager\Controller\ListController
Definition: ListController.php:49
‪TYPO3\CMS\Extensionmanager\Controller\ListController\showAllVersionsAction
‪showAllVersionsAction(string $extensionKey)
Definition: ListController.php:194
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry
Definition: RemoteRegistry.php:26
‪TYPO3\CMS\Extensionmanager\Controller\ListController\unresolvedDependenciesAction
‪unresolvedDependenciesAction(string $extensionKey, array $returnAction)
Definition: ListController.php:108