*/
class IconRegistry implements \TYPO3\CMS\Core\SingletonInterface
{
+ /**
+ * @var bool
+ */
+ protected $fullInitialized = false;
+
/**
* @var bool
*/
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)
*/
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);
*/
public function getAllRegisteredIconIdentifiers()
{
+ if (!$this->fullInitialized) {
+ $this->initialize();
+ }
return array_keys($this->icons);
}
*/
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']);
$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'])) {