[BUGFIX] Fixes fatal error when getting other exts

Moving part into the if-clause where
$extension is checked for a valid object

Change-Id: I7b61dbcfc074f41b7fdfde544a886d9b85b42684
Resolves: #57908
Reviewed-on: https://review.typo3.org/29463
Reviewed-by: Philipp Gampe
Reviewed-by: Thomas Löffler
Tested-by: Thomas Löffler