[TASK] Streamline deprecation handling in icon API 29/55829/3
authorOliver Hader <oliver@typo3.org>
Tue, 20 Feb 2018 15:44:25 +0000 (16:44 +0100)
committerFrank Naegler <frank.naegler@typo3.org>
Tue, 20 Feb 2018 22:17:55 +0000 (23:17 +0100)
Icon API supports some basic handling of deprecated icons
as well as keeping track of replacements. However, it is
not possible to automatically benefit from these
replacements in case they are defined.

This change tackles the following:

* bug when logging deprecated icon identifiers due to
  mismatching sprintf arguments
* automatically making use of available replacements
  instead of throwing exception
* possibility to retrieve deprecated icons and
  replacements (in order to render them in ext:styleguide)

Resolves: #83978
Releases: master
Change-Id: I7faceebc30cca0cd1f392b4845d85ac2e5bf7307
Reviewed-on: https://review.typo3.org/55829
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/core/Classes/Imaging/IconFactory.php
typo3/sysext/core/Classes/Imaging/IconRegistry.php

index f2fe258..6416893 100644 (file)
@@ -105,7 +105,12 @@ class IconFactory
         if (!empty(static::$iconCache[$cacheIdentifier])) {
             return static::$iconCache[$cacheIdentifier];
         }
-        if (!$this->iconRegistry->isRegistered($identifier)) {
+
+        if (
+            !$this->iconRegistry->isDeprecated($identifier)
+            && !$this->iconRegistry->isRegistered($identifier)
+        ) {
+            // in case icon identifier is neither deprecated nor registered
             $identifier = $this->iconRegistry->getDefaultIconIdentifier();
         }
 
index efa23ce..531a333 100644 (file)
@@ -718,20 +718,21 @@ class IconRegistry implements SingletonInterface
         if (!$this->fullInitialized) {
             $this->initialize();
         }
-        if (!$this->isRegistered($identifier)) {
-            throw new Exception('Icon with identifier "' . $identifier . '" is not registered"', 1437425804);
-        }
         if ($this->isDeprecated($identifier)) {
-            $replacement = $this->deprecatedIcons[$identifier];
+            $replacement = $this->deprecatedIcons[$identifier] ?? null;
             if (!empty($replacement)) {
                 $message = 'The icon "%s" is deprecated since TYPO3 v9 and will be removed in TYPO3 v10. Please use "%s" instead.';
-                $arguments = [$replacement];
+                $arguments = [$identifier, $replacement];
+                $identifier = $replacement;
             } else {
                 $message = 'The icon "%s" is deprecated since TYPO3 v9 and will be removed in TYPO3 v10.';
-                $arguments = [];
+                $arguments = [$identifier];
             }
             trigger_error(vsprintf($message, $arguments), E_USER_DEPRECATED);
         }
+        if (!$this->isRegistered($identifier)) {
+            throw new Exception('Icon with identifier "' . $identifier . '" is not registered"', 1437425804);
+        }
         return $this->icons[$identifier];
     }
 
@@ -747,6 +748,14 @@ class IconRegistry implements SingletonInterface
     }
 
     /**
+     * @return array
+     */
+    public function getDeprecatedIcons(): array
+    {
+        return $this->deprecatedIcons;
+    }
+
+    /**
      * @param string $fileExtension
      * @return string
      */