From 0a96b82b9dde49baa9841d5f432672ebdafdd1d6 Mon Sep 17 00:00:00 2001 From: Ivo Valchev Date: Fri, 31 Jul 2020 15:42:09 +0200 Subject: [PATCH 1/3] Add image.extension value --- src/Controller/ImageController.php | 4 ++-- src/Entity/Field/FileExtrasTrait.php | 5 +++++ src/Entity/Field/FileField.php | 2 ++ src/Entity/Field/ImageField.php | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Controller/ImageController.php b/src/Controller/ImageController.php index ba1fdd19f..9149c3d92 100644 --- a/src/Controller/ImageController.php +++ b/src/Controller/ImageController.php @@ -157,9 +157,9 @@ private function parseParameters(string $paramString): void private function isSvg(string $filename): bool { - $pathinfo = pathinfo($filename); + $extension = pathinfo($filename, PATHINFO_EXTENSION); - return array_key_exists('extension', $pathinfo) && $pathinfo['extension'] === 'svg'; + return $extension === 'svg'; } private function isImage(string $filename): bool diff --git a/src/Entity/Field/FileExtrasTrait.php b/src/Entity/Field/FileExtrasTrait.php index 880c64a28..70a2b4757 100644 --- a/src/Entity/Field/FileExtrasTrait.php +++ b/src/Entity/Field/FileExtrasTrait.php @@ -41,4 +41,9 @@ private function getHost(Request $request) return $host . ':' . $port; } + + private function getExtension(): string + { + return pathinfo($this->__toString(), PATHINFO_EXTENSION); + } } diff --git a/src/Entity/Field/FileField.php b/src/Entity/Field/FileField.php index 9b9ed300e..4a8344cb1 100644 --- a/src/Entity/Field/FileField.php +++ b/src/Entity/Field/FileField.php @@ -25,6 +25,7 @@ private function getFieldBase() 'path' => '', 'fieldname' => '', 'url' => '', + 'extension' => '', ]; } @@ -50,6 +51,7 @@ public function getValue(): array // Generate a URL $value['path'] = $this->getPath(); $value['url'] = $this->getUrl(); + $value['extension'] = $this->getExtension(); return $value; } diff --git a/src/Entity/Field/ImageField.php b/src/Entity/Field/ImageField.php index eb99ec845..aed43cfbb 100644 --- a/src/Entity/Field/ImageField.php +++ b/src/Entity/Field/ImageField.php @@ -33,6 +33,7 @@ private function getFieldBase() 'fieldname' => '', 'alt' => '', 'url' => '', + 'extension' => '', ]; } @@ -58,6 +59,7 @@ public function getValue(): array // Generate a URL $value['path'] = $this->getPath(); $value['url'] = $this->getUrl(); + $value['extension'] = $this->getExtension(); $thumbPackage = new PathPackage('/thumbs/', new EmptyVersionStrategy()); $thumbnailHelper = new ThumbnailHelper(); From 5f475e159ccc3c3cac3b8e5d20466e9d0a4d0d98 Mon Sep 17 00:00:00 2001 From: Ivo Valchev Date: Fri, 31 Jul 2020 15:59:58 +0200 Subject: [PATCH 2/3] Fix tests --- tests/api/get_content.feature | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/api/get_content.feature b/tests/api/get_content.feature index 6f0c9e05a..4dde8da2e 100644 --- a/tests/api/get_content.feature +++ b/tests/api/get_content.feature @@ -28,7 +28,8 @@ Feature: Get content with API "media": @string@, "url": @string@, "thumbnail": @string@, - "fieldname": @string@ + "fieldname": @string@, + "extension": @string }, "@*@": "@*@" }, @@ -74,7 +75,8 @@ Feature: Get content with API "media": @string@, "url": @string@, "thumbnail": @string@, - "fieldname": @string@ + "fieldname": @string@, + "extension": @string }, "@*@": "@*@" }, @@ -125,7 +127,8 @@ Feature: Get content with API "media": @string@, "url": @string@, "thumbnail": @string@, - "fieldname": @string@ + "fieldname": @string@, + "extension": @string }, "@*@": "@*@" }, @@ -189,7 +192,8 @@ Feature: Get content with API "media": @string@, "url": @string@, "thumbnail": @string@, - "fieldname": @string@ + "fieldname": @string@, + "extension": @string@ }, "@*@": "@*@" }, @@ -250,7 +254,8 @@ Feature: Get content with API "media": @string@, "url": @string@, "thumbnail": @string@, - "fieldname": @string@ + "fieldname": @string@, + "extension": @string@ }, "@*@": "@*@" }, From 69fd903be2fec8b9bca0dc43c45789ad02d240d9 Mon Sep 17 00:00:00 2001 From: Ivo Valchev Date: Fri, 31 Jul 2020 16:58:16 +0200 Subject: [PATCH 3/3] more fixes! --- tests/api/get_content.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/api/get_content.feature b/tests/api/get_content.feature index 4dde8da2e..44062a5a9 100644 --- a/tests/api/get_content.feature +++ b/tests/api/get_content.feature @@ -29,7 +29,7 @@ Feature: Get content with API "url": @string@, "thumbnail": @string@, "fieldname": @string@, - "extension": @string + "extension": @string@ }, "@*@": "@*@" }, @@ -76,7 +76,7 @@ Feature: Get content with API "url": @string@, "thumbnail": @string@, "fieldname": @string@, - "extension": @string + "extension": @string@ }, "@*@": "@*@" }, @@ -128,7 +128,7 @@ Feature: Get content with API "url": @string@, "thumbnail": @string@, "fieldname": @string@, - "extension": @string + "extension": @string@ }, "@*@": "@*@" },