4141 * @api
4242 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
4343 * @SuppressWarnings(PHPMD.TooManyFields)
44+ * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
4445 * @since 101.0.0
4546 */
4647class DataProvider extends ModifierPoolDataProvider
@@ -176,6 +177,10 @@ class DataProvider extends ModifierPoolDataProvider
176177 * @var AuthorizationInterface
177178 */
178179 private $ auth ;
180+ /**
181+ * @var Image
182+ */
183+ private $ categoryImage ;
179184
180185 /**
181186 * @param string $name
@@ -196,6 +201,7 @@ class DataProvider extends ModifierPoolDataProvider
196201 * @param ScopeOverriddenValue|null $scopeOverriddenValue
197202 * @param ArrayManager|null $arrayManager
198203 * @param FileInfo|null $fileInfo
204+ * @param Image|null $categoryImage
199205 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
200206 */
201207 public function __construct (
@@ -216,7 +222,8 @@ public function __construct(
216222 ?ArrayUtils $ arrayUtils = null ,
217223 ScopeOverriddenValue $ scopeOverriddenValue = null ,
218224 ArrayManager $ arrayManager = null ,
219- FileInfo $ fileInfo = null
225+ FileInfo $ fileInfo = null ,
226+ ?Image $ categoryImage = null
220227 ) {
221228 $ this ->eavValidationRules = $ eavValidationRules ;
222229 $ this ->collection = $ categoryCollectionFactory ->create ();
@@ -232,6 +239,7 @@ public function __construct(
232239 ObjectManager::getInstance ()->get (ScopeOverriddenValue::class);
233240 $ this ->arrayManager = $ arrayManager ?: ObjectManager::getInstance ()->get (ArrayManager::class);
234241 $ this ->fileInfo = $ fileInfo ?: ObjectManager::getInstance ()->get (FileInfo::class);
242+ $ this ->categoryImage = $ categoryImage ?? ObjectManager::getInstance ()->get (Image::class);
235243
236244 parent ::__construct ($ name , $ primaryFieldName , $ requestFieldName , $ meta , $ data , $ pool );
237245 }
@@ -601,11 +609,7 @@ private function convertValues($category, $categoryData): array
601609 // phpcs:ignore Magento2.Functions.DiscouragedFunction
602610 $ categoryData [$ attributeCode ][0 ]['name ' ] = basename ($ fileName );
603611
604- if ($ this ->fileInfo ->isBeginsWithMediaDirectoryPath ($ fileName )) {
605- $ categoryData [$ attributeCode ][0 ]['url ' ] = $ fileName ;
606- } else {
607- $ categoryData [$ attributeCode ][0 ]['url ' ] = $ category ->getImageUrl ($ attributeCode );
608- }
612+ $ categoryData [$ attributeCode ][0 ]['url ' ] = $ this ->categoryImage ->getUrl ($ category , $ attributeCode );
609613
610614 $ categoryData [$ attributeCode ][0 ]['size ' ] = isset ($ stat ) ? $ stat ['size ' ] : 0 ;
611615 $ categoryData [$ attributeCode ][0 ]['type ' ] = $ mime ;
0 commit comments