‪TYPO3CMS  11.5
ListController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ResponseInterface;
27 use TYPO3\CMS\Core\Page\PageRenderer;
41 
47 {
48  protected PageRenderer ‪$pageRenderer;
53 
54  public function ‪__construct(
55  PageRenderer ‪$pageRenderer,
60  ) {
61  $this->pageRenderer = ‪$pageRenderer;
62  $this->extensionRepository = ‪$extensionRepository;
63  $this->listUtility = ‪$listUtility;
64  $this->dependencyUtility = ‪$dependencyUtility;
65  $this->iconFactory = ‪$iconFactory;
66  }
67 
71  public function ‪initializeAction()
72  {
73  $this->pageRenderer->addInlineLanguageLabelFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
74  $this->settings['offlineMode'] = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'offlineMode');
75  }
76 
80  protected function ‪addComposerModeNotification()
81  {
83  $this->‪addFlashMessage(
85  'composerStrictMode.message',
86  'extensionmanager'
87  ) ?? '',
89  'composerMode.title',
90  'extensionmanager'
91  ) ?? '',
93  );
94  }
95  }
96 
100  public function ‪indexAction(): ResponseInterface
101  {
102  if ($this->request->hasArgument('filter') && is_string($this->request->getArgument('filter'))) {
103  $filter = $this->request->getArgument('filter');
104  $this->‪saveBackendUserFilter($filter);
105  } else {
106  $filter = $this->‪getBackendUserFilter();
107  }
108 
110  $isComposerMode = ‪Environment::isComposerMode();
111  $availableAndInstalledExtensions = $this->‪enrichExtensionsWithViewInformation(
112  $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation($filter),
113  $isComposerMode
114  );
115  ksort($availableAndInstalledExtensions);
116  $this->view->assignMultiple(
117  [
118  'extensions' => $availableAndInstalledExtensions,
119  'isComposerMode' => $isComposerMode,
120  'typeFilter' => $filter ?: 'All',
121  // Sort extension by update state. This is only automatically set for non-composer
122  // mode and only takes effect if at least one extension can be updated.
123  'sortByUpdate' => $this->‪extensionsWithUpdate($availableAndInstalledExtensions) !== [] && !$isComposerMode,
124  ]
125  );
126  $this->‪handleTriggerArguments();
127 
128  $moduleTemplate = $this->‪initializeModuleTemplate($this->request);
129  $moduleTemplate = $this->‪registerDocHeaderButtons($moduleTemplate);
130  $moduleTemplate->setContent($this->view->render());
131  return $this->‪htmlResponse($moduleTemplate->renderContent());
132  }
133 
140  public function ‪unresolvedDependenciesAction($extensionKey): ResponseInterface
141  {
142  $availableExtensions = $this->listUtility->getAvailableExtensions();
143  if (isset($availableExtensions[$extensionKey])) {
144  $extensionArray = $this->listUtility->enrichExtensionsWithEmConfAndTerInformation(
145  [
146  $extensionKey => $availableExtensions[$extensionKey],
147  ]
148  );
149  $extension = ‪Extension::createFromExtensionArray($extensionArray[$extensionKey]);
150  } else {
151  throw new ‪ExtensionManagerException('Extension ' . $extensionKey . ' is not available', 1402421007);
152  }
153  $this->dependencyUtility->checkDependencies($extension);
154  $this->view->assign('extension', $extension);
155  $this->view->assign('unresolvedDependencies', $this->dependencyUtility->getDependencyErrors());
156 
157  $moduleTemplate = $this->‪initializeModuleTemplate($this->request);
158  $moduleTemplate->setContent($this->view->render());
159  return $this->‪htmlResponse($moduleTemplate->renderContent());
160  }
161 
170  public function ‪terAction($search = '', int $currentPage = 1): ResponseInterface
171  {
173  $search = trim($search);
174  if (!empty($search)) {
175  $extensions = $this->extensionRepository->findByTitleOrAuthorNameOrExtensionKey($search);
176  $paginator = new ‪ArrayPaginator($extensions, $currentPage);
177  $tableId = 'terSearchTable';
178  } else {
180  $extensions = $this->extensionRepository->findAll();
181  $paginator = new ‪QueryResultPaginator($extensions, $currentPage);
182  $tableId = 'terTable';
183  }
184  $pagination = new ‪SimplePagination($paginator);
185  $availableAndInstalledExtensions = $this->listUtility->getAvailableAndInstalledExtensions($this->listUtility->getAvailableExtensions());
186  $this->view->assignMultiple([
187  'extensions' => $extensions,
188  'paginator' => $paginator,
189  'pagination' => $pagination,
190  'search' => $search,
191  'availableAndInstalled' => $availableAndInstalledExtensions,
192  'actionName' => 'ter',
193  'tableId' => $tableId,
194  ]);
195 
196  $moduleTemplate = $this->‪initializeModuleTemplate($this->request);
197  $moduleTemplate = $this->‪registerDocHeaderButtons($moduleTemplate);
198  $moduleTemplate->setContent($this->view->render());
199  return $this->‪htmlResponse($moduleTemplate->renderContent());
200  }
201 
208  public function ‪distributionsAction($showUnsuitableDistributions = false): ResponseInterface
209  {
210  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Extensionmanager/DistributionImage');
212  $importExportInstalled = ‪ExtensionManagementUtility::isLoaded('impexp');
213  if ($importExportInstalled) {
214  try {
215  $remoteRegistry = GeneralUtility::makeInstance(RemoteRegistry::class);
216  foreach ($remoteRegistry->getListableRemotes() as $remote) {
217  $remote->getAvailablePackages();
218  }
219  } catch (‪ExtensionManagerException $e) {
220  $this->‪addFlashMessage($e->getMessage(), $e->getCode(), ‪FlashMessage::ERROR);
221  }
222 
223  $officialDistributions = $this->extensionRepository->findAllOfficialDistributions($showUnsuitableDistributions);
224  $communityDistributions = $this->extensionRepository->findAllCommunityDistributions($showUnsuitableDistributions);
225 
226  $this->view->assign('officialDistributions', $officialDistributions);
227  $this->view->assign('communityDistributions', $communityDistributions);
228  }
229  $this->view->assign('enableDistributionsView', $importExportInstalled);
230  $this->view->assign('showUnsuitableDistributions', $showUnsuitableDistributions);
231 
232  $moduleTemplate = $this->‪initializeModuleTemplate($this->request);
233  $moduleTemplate->setContent($this->view->render());
234  return $this->‪htmlResponse($moduleTemplate->renderContent());
235  }
236 
243  public function ‪showAllVersionsAction($extensionKey): ResponseInterface
244  {
245  $currentVersion = $this->extensionRepository->findOneByCurrentVersionByExtensionKey($extensionKey);
246  $extensions = $this->extensionRepository->findByExtensionKeyOrderedByVersion($extensionKey);
247 
248  $this->view->assignMultiple(
249  [
250  'extensionKey' => $extensionKey,
251  'currentVersion' => $currentVersion,
252  'extensions' => $extensions,
253  ]
254  );
255 
256  $moduleTemplate = $this->‪initializeModuleTemplate($this->request);
257  $moduleTemplate = $this->‪registerDocHeaderButtons($moduleTemplate);
258  $moduleTemplate->setContent($this->view->render());
259  return $this->‪htmlResponse($moduleTemplate->renderContent());
260  }
261 
266  {
268  return $moduleTemplate;
269  }
270 
271  $buttonBar = $moduleTemplate->‪getDocHeaderComponent()->‪getButtonBar();
272 
273  if ($this->actionMethodName === 'showAllVersionsAction') {
274  $action = $this->request->hasArgument('returnTo') ? $this->request->getArgument('returnTo') : 'ter';
275  $uri = $this->uriBuilder->reset()->uriFor(in_array($action, ['index', 'ter'], true) ? $action : 'ter', [], 'List');
276  $title = $this->‪translate('extConfTemplate.backToList');
277  $icon = $this->iconFactory->getIcon('actions-view-go-back', ‪Icon::SIZE_SMALL);
278  $classes = '';
279  } else {
280  $uri = $this->uriBuilder->reset()->uriFor('form', [], 'UploadExtensionFile');
281  $title = $this->‪translate('extensionList.uploadExtension');
282  $icon = $this->iconFactory->getIcon('actions-edit-upload', ‪Icon::SIZE_SMALL);
283  $classes = 't3js-upload';
284  }
285  $button = $buttonBar->makeLinkButton()
286  ->setHref($uri)
287  ->setTitle($title)
288  ->setClasses($classes)
289  ->setIcon($icon);
290  $buttonBar->addButton($button, ‪ButtonBar::BUTTON_POSITION_LEFT);
291 
292  return $moduleTemplate;
293  }
294 
295  protected function ‪getBackendUserFilter(): string
296  {
297  return (string)($this->‪getBackendUserAuthentication()->getModuleData('ExtensionManager')['filter'] ?? '');
298  }
299 
300  protected function ‪saveBackendUserFilter(string $filter): void
301  {
302  $this->‪getBackendUserAuthentication()->pushModuleData('ExtensionManager', ['filter' => $filter]);
303  }
304 
305  protected function ‪enrichExtensionsWithViewInformation(array $availableAndInstalledExtensions, bool $isComposerMode): array
306  {
307  $isOfflineMode = (bool)($this->settings['offlineMode'] ?? false);
308 
309  foreach ($availableAndInstalledExtensions as &$extension) {
310  $extension['updateIsBlocked'] = $isComposerMode || $isOfflineMode || ($extension['state'] ?? '') === 'excludeFromUpdates';
311  $extension['sortUpdate'] = 2;
312  if ($extension['updateAvailable'] ?? false) {
313  $extension['sortUpdate'] = (int)$extension['updateIsBlocked'];
314  }
315  }
316 
317  return $availableAndInstalledExtensions;
318  }
319 
320  protected function ‪extensionsWithUpdate(array $availableAndInstalledExtensions): array
321  {
322  return array_filter($availableAndInstalledExtensions, static function ($extension) {
323  return $extension['updateAvailable'] ?? false;
324  });
325  }
326 
328  {
329  return ‪$GLOBALS['BE_USER'];
330  }
331 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Extensionmanager\Controller\ListController\indexAction
‪indexAction()
Definition: ListController.php:100
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_LEFT
‪const BUTTON_POSITION_LEFT
Definition: ButtonBar.php:36
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:32
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController\translate
‪string translate($key, $arguments=null)
Definition: AbstractController.php:44
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\htmlResponse
‪ResponseInterface htmlResponse(string $html=null)
Definition: ActionController.php:1067
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility
Definition: LocalizationUtility.php:33
‪TYPO3\CMS\Extensionmanager\Controller\AbstractModuleController
Definition: AbstractModuleController.php:28
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:28
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:45
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Extensionmanager\Controller\ListController\addComposerModeNotification
‪addComposerModeNotification()
Definition: ListController.php:80
‪TYPO3\CMS\Extbase\Pagination\QueryResultPaginator
Definition: QueryResultPaginator.php:24
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension\createFromExtensionArray
‪static Extension createFromExtensionArray(array $extensionArray)
Definition: Extension.php:625
‪TYPO3\CMS\Extensionmanager\Controller\ListController\$dependencyUtility
‪DependencyUtility $dependencyUtility
Definition: ListController.php:51
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Extensionmanager\Controller\ListController\registerDocHeaderButtons
‪registerDocHeaderButtons(ModuleTemplate $moduleTemplate)
Definition: ListController.php:265
‪TYPO3\CMS\Extensionmanager\Controller
Definition: AbstractController.php:16
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\addFlashMessage
‪addFlashMessage($messageBody, $messageTitle='', $severity=AbstractMessage::OK, $storeInSession=true)
Definition: ActionController.php:828
‪TYPO3\CMS\Extensionmanager\Controller\ListController\__construct
‪__construct(PageRenderer $pageRenderer, ExtensionRepository $extensionRepository, ListUtility $listUtility, DependencyUtility $dependencyUtility, IconFactory $iconFactory)
Definition: ListController.php:54
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:40
‪TYPO3\CMS\Extensionmanager\Controller\ListController\terAction
‪ResponseInterface terAction($search='', int $currentPage=1)
Definition: ListController.php:170
‪TYPO3\CMS\Extensionmanager\Controller\ListController\initializeAction
‪initializeAction()
Definition: ListController.php:71
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:46
‪TYPO3\CMS\Core\Pagination\SimplePagination
Definition: SimplePagination.php:21
‪TYPO3\CMS\Extensionmanager\Controller\ListController\$pageRenderer
‪PageRenderer $pageRenderer
Definition: ListController.php:48
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Extensionmanager\Controller\ListController\$iconFactory
‪IconFactory $iconFactory
Definition: ListController.php:52
‪TYPO3\CMS\Extensionmanager\Controller\ListController\enrichExtensionsWithViewInformation
‪enrichExtensionsWithViewInformation(array $availableAndInstalledExtensions, bool $isComposerMode)
Definition: ListController.php:305
‪TYPO3\CMS\Extensionmanager\Utility\DependencyUtility
Definition: DependencyUtility.php:35
‪TYPO3\CMS\Extensionmanager\Controller\ListController\getBackendUserAuthentication
‪getBackendUserAuthentication()
Definition: ListController.php:327
‪TYPO3\CMS\Extensionmanager\Controller\ListController\getBackendUserFilter
‪getBackendUserFilter()
Definition: ListController.php:295
‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
Definition: ExtensionRepository.php:34
‪TYPO3\CMS\Extbase\Utility\LocalizationUtility\translate
‪static string null translate(string $key, ?string $extensionName=null, array $arguments=null, string $languageKey=null, array $alternativeLanguageKeys=null)
Definition: LocalizationUtility.php:67
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:23
‪TYPO3\CMS\Extbase\Persistence\QueryResultInterface
Definition: QueryResultInterface.php:22
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Extensionmanager\Controller\ListController\$listUtility
‪ListUtility $listUtility
Definition: ListController.php:50
‪TYPO3\CMS\Extensionmanager\Controller\ListController\saveBackendUserFilter
‪saveBackendUserFilter(string $filter)
Definition: ListController.php:300
‪TYPO3\CMS\Extensionmanager\Controller\ListController\showAllVersionsAction
‪ResponseInterface showAllVersionsAction($extensionKey)
Definition: ListController.php:243
‪TYPO3\CMS\Extensionmanager\Controller\ListController\extensionsWithUpdate
‪extensionsWithUpdate(array $availableAndInstalledExtensions)
Definition: ListController.php:320
‪TYPO3\CMS\Backend\Template\Components\DocHeaderComponent\getButtonBar
‪ButtonBar getButtonBar()
Definition: DocHeaderComponent.php:88
‪TYPO3\CMS\Core\Pagination\ArrayPaginator
Definition: ArrayPaginator.php:21
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:152
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Extensionmanager\Controller\AbstractModuleController\initializeModuleTemplate
‪initializeModuleTemplate(ServerRequestInterface $request)
Definition: AbstractModuleController.php:56
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:43
‪TYPO3\CMS\Extensionmanager\Controller\ListController
Definition: ListController.php:47
‪TYPO3\CMS\Backend\Template\ModuleTemplate\getDocHeaderComponent
‪DocHeaderComponent getDocHeaderComponent()
Definition: ModuleTemplate.php:370
‪TYPO3\CMS\Extensionmanager\Controller\ListController\distributionsAction
‪ResponseInterface distributionsAction($showUnsuitableDistributions=false)
Definition: ListController.php:208
‪TYPO3\CMS\Extensionmanager\Controller\ListController\unresolvedDependenciesAction
‪ResponseInterface unresolvedDependenciesAction($extensionKey)
Definition: ListController.php:140
‪TYPO3\CMS\Extensionmanager\Controller\AbstractController\handleTriggerArguments
‪handleTriggerArguments()
Definition: AbstractController.php:54
‪TYPO3\CMS\Extensionmanager\Controller\ListController\$extensionRepository
‪ExtensionRepository $extensionRepository
Definition: ListController.php:49
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key)
Definition: ExtensionManagementUtility.php:114
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry
Definition: RemoteRegistry.php:26