TYPO3  7.6
lang/Classes/Domain/Repository/ExtensionRepository.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Lang\Domain\Repository;
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 
18 
23 {
27  protected $objectManager;
28 
32  protected $listUtility;
33 
37  protected $extensions = array();
38 
42  public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
43  {
44  $this->objectManager = $objectManager;
45  }
46 
50  public function injectListUtility(\TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility)
51  {
52  $this->listUtility = $listUtility;
53  }
54 
60  public function findAll()
61  {
62  if (empty($this->extensions)) {
63  $extensions = $this->listUtility->getAvailableAndInstalledExtensionsWithAdditionalInformation();
64  foreach ($extensions as $entry) {
66  $extension = $this->objectManager->get(
67  \TYPO3\CMS\Lang\Domain\Model\Extension::class,
68  $entry['key'],
69  $entry['title'],
70  $this->getExtensionIconWithPath($entry)
71  );
72  $extension->setVersionFromString($entry['version']);
73  if ($entry['ext_icon_width'] > 0) {
74  $extension->setIconWidth($entry['ext_icon_width']);
75  }
76  if ($entry['ext_icon_height'] > 0) {
77  $extension->setIconHeight($entry['ext_icon_height']);
78  }
79 
80  $this->extensions[$entry['key']] = $extension;
81  }
82  ksort($this->extensions);
83  }
84  return $this->extensions;
85  }
86 
92  public function countAll()
93  {
94  $extensions = $this->findAll();
95  return count($extensions);
96  }
97 
104  public function findOneByOffset($offset)
105  {
106  $extensions = $this->findAll();
107  $extensions = array_values($extensions);
108  $offset = (int)$offset;
109  if (!empty($extensions[$offset])) {
110  return $extensions[$offset];
111  }
112  return null;
113  }
114 
121  protected function getExtensionIconWithPath($extensionEntry)
122  {
123  $extensionIcon = $GLOBALS['TYPO3_LOADED_EXT'][$extensionEntry['key']]['ext_icon'];
124  if (empty($extensionIcon)) {
125  $extensionIcon = ExtensionManagementUtility::getExtensionIcon(PATH_site . $extensionEntry['siteRelPath'] . '/');
126  }
127  if (empty($extensionIcon)) {
128  $extensionIcon = '/typo3/sysext/core/ext_icon.png';
129  } else {
130  $extensionIcon = '../' . $extensionEntry['siteRelPath'] . '/' . $extensionIcon;
131  }
132  return $extensionIcon;
133  }
134 }