From 528cf702f2524736606ef1277603fca54af1b9d4 Mon Sep 17 00:00:00 2001 From: Frank Naegler Date: Mon, 25 Jan 2016 13:45:17 +0100 Subject: [PATCH] [BUGFIX] Refactor the initialize process of IconRegistry MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fix a problem in case of IconFactory not being fully initialized. Resolves: #72926 Releases: master, 7.6 Change-Id: Iaeb511e4a2c681a135b2ec993a4b2f91e5bd53e8 Reviewed-on: https://review.typo3.org/46226 Reviewed-by: Stephan Großberndt Reviewed-by: Andreas Allacher Tested-by: Andreas Allacher Reviewed-by: Benni Mack Tested-by: Benni Mack --- .../core/Classes/Imaging/IconRegistry.php | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/typo3/sysext/core/Classes/Imaging/IconRegistry.php b/typo3/sysext/core/Classes/Imaging/IconRegistry.php index 03d3bd589007..33268ecdc9b8 100644 --- a/typo3/sysext/core/Classes/Imaging/IconRegistry.php +++ b/typo3/sysext/core/Classes/Imaging/IconRegistry.php @@ -27,6 +27,11 @@ use TYPO3\CMS\Core\Utility\StringUtility; */ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface { + /** + * @var bool + */ + protected $fullInitialized = false; + /** * @var bool */ @@ -2643,29 +2648,45 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface protected $defaultIconIdentifier = 'default-not-found'; /** - * The constructor - */ + * The constructor + */ public function __construct() + { + $this->initialize(); + } + + /** + * Initialize the registry + * This method can be called multiple times, depending on initialization status. + * In some cases e.g. TCA is not available, the method must be called multiple times. + */ + protected function initialize() { if (!$this->tcaInitialized && !empty($GLOBALS['TCA'])) { $this->registerTCAIcons(); } - $this->registerFlags(); + if (!$this->flagsInitialized) { + $this->registerFlags(); + } + if ($this->tcaInitialized && $this->flagsInitialized) { + $this->fullInitialized = true; + } } /** * @param string $identifier - * * @return bool */ public function isRegistered($identifier) { + if (!$this->fullInitialized) { + $this->initialize(); + } return isset($this->icons[$identifier]); } /** * @param string $identifier - * * @return bool */ public function isDeprecated($identifier) @@ -2732,13 +2753,8 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface */ public function getIconConfigurationByIdentifier($identifier) { - // In some cases TCA is not available, auto register TCA icons - // only the first time the TCA is available - if (!$this->tcaInitialized && !empty($GLOBALS['TCA'])) { - $this->registerTCAIcons(); - } - if ($this->flagsInitialized) { - $this->registerFlags(); + if (!$this->fullInitialized) { + $this->initialize(); } if (!$this->isRegistered($identifier)) { throw new Exception('Icon with identifier "' . $identifier . '" is not registered"', 1437425804); @@ -2773,6 +2789,9 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface */ public function getAllRegisteredIconIdentifiers() { + if (!$this->fullInitialized) { + $this->initialize(); + } return array_keys($this->icons); } @@ -2808,11 +2827,6 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface */ protected function registerTCAIcons() { - // if TCA is not available, e.g. for some unit test, return directly - if (!is_array($GLOBALS['TCA'])) { - return; - } - $resultArray = array(); $tcaTables = array_keys($GLOBALS['TCA']); @@ -2823,7 +2837,7 @@ class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface $tcaCtrl = $GLOBALS['TCA'][$tableName]['ctrl']; $icon = null; $iconIdentifier = 'tcarecords-' . $tableName . '-default'; - if ($this->isRegistered($iconIdentifier)) { + if (isset($this->icons[$iconIdentifier])) { continue; } if (isset($tcaCtrl['iconfile'])) { -- 2.20.1