[TYPO3-dev] how to iterate over LoadedExtensionArrayElement

Alexander Stehlik alexander.stehlik at gmail.com
Wed Nov 6 09:59:25 CET 2013


Sorry, just got the point with the replacement of the underscore in the 
Extension key.

You can have a look a a patch in gerrit, that is also iterating over the 
active packages:

https://review.typo3.org/#/c/25002/2/typo3/sysext/impexp/Classes/Controller/ImportExportController.php

Code looks basically like:

$packageManager = 
GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Package\\PackageManager');
foreach ($packageManager->getActivePackages() as $package) {
	$packageKey = $package->getPackageKey();
	... // do your own stuff here
}

Hope this helps.

Cheers,
Alex

Am 06.11.2013 09:50, schrieb Alexander Stehlik:
>
> Hi Franz,
>
> is there a reason why you do not use
>
> \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded()
>
> for that?
>
> The code in this method is pretty simple:
>
> $isLoaded = static::$packageManager->isPackageActive($key);
> if ($exitOnError && !$isLoaded) {
>      throw new \BadFunctionCallException('TYPO3 Fatal Error: Extension
> "' . $key . '" is not loaded!', 1270853910);
> }
> return $isLoaded;
>
> Of course you could also directly use the isPackageActive() in the
> PackageManager.
>
> I hope I got the point of your question right ;)
>
> Cheers,
> Alex
>
>
> Am 04.11.2013 14:40, schrieb Franz Holzinger:
>> Hello,
>>
>> since TYPO3 6.2 the TYPO3_LOADED_EXT envirnoment variable gives an
>> object of the class TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray.
>> If I iterate over its elements in a foreach:
>>
>> foreach ($loadedExt as $k => $v) {
>> ..
>> }
>>
>> then I get element objects of the class
>> TYPO3\CMS\Core\Compatibility\LoadedExtensionArrayElement.
>>
>> But how must the PHP code iterate over this element in order to retrieve
>> the information if an extension key is installed or not? When I debug
>> the object, then it is very big. I do not find the solution.
>>
>>
>> In TYPO3 4.x this code could discover if an extension $rawKey has been
>> installed.
>>
>> ----------------
>> class tx_div2007 {
>>
>> ...
>>
>> /**
>>   * Check if the given extension key is within the loaded extensions
>>   *
>>   * The key can be given in the regular format or with underscores
>> stripped.
>>   *
>>   * @param    string        extension key to check
>>   * @return    boolean        is the key valid?
>>   */
>> public function getValidKey ($rawKey) {
>>
>> $loadedExt = self::getGlobal('TYPO3_LOADED_EXT');
>> $uKeys = array_keys($loadedExt);
>> foreach((array)$uKeys as $uKey) {
>>      if( str_replace('_', '', $uKey) == str_replace('_', '', $rawKey) ){
>>          $result =  $uKey;
>>      }
>> }
>>
>> return $result ? $result : FALSE;
>>
>>
>> }
>> ...
>>
>> }
>> --------------
>> This does not work any more under TYPO3 6.x.
>>
>>
>> How must I change this code for TYPO3 6.x in order to use the iterator
>> LoadedExtensionArrayElement?
>>
>> ./typo3/sysext/core/Classes/Compatibility/LoadedExtensionArrayElement.php
>>
>>
>> - Franz
>>
>




More information about the TYPO3-dev mailing list