From f6b0563e7f589b82480e1697dd187cf9991d5e6b Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Mon, 18 Nov 2019 20:24:09 +0100 Subject: [PATCH 1/4] Make 'extras' only return values for Image, not the entire ImageField object --- src/Twig/ContentExtension.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Twig/ContentExtension.php b/src/Twig/ContentExtension.php index 7ecd76b4..92e792da 100644 --- a/src/Twig/ContentExtension.php +++ b/src/Twig/ContentExtension.php @@ -125,13 +125,13 @@ class ContentExtension extends AbstractExtension } /** - * @return ImageField|string|null + * @return ImageField|array|null */ - public function getImage(Content $content, bool $onlyPath = false) + public function getImage(Content $content, bool $onlyValues = true) { foreach ($content->getFields() as $field) { if ($field instanceof ImageField) { - return $onlyPath ? $field->getPath() : $field; + return $onlyValues ? $field->getValue() : $field; } } From cb0411f111e86feb187dc0f52ca0fe09fc6ae80b Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Mon, 18 Nov 2019 20:38:31 +0100 Subject: [PATCH 2/4] Fix Weird-ass ContentExtensionSpec test --- tests/spec/Bolt/Twig/ContentExtensionSpec.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/spec/Bolt/Twig/ContentExtensionSpec.php b/tests/spec/Bolt/Twig/ContentExtensionSpec.php index d907e976..8abf68c9 100644 --- a/tests/spec/Bolt/Twig/ContentExtensionSpec.php +++ b/tests/spec/Bolt/Twig/ContentExtensionSpec.php @@ -24,7 +24,7 @@ use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; class ContentExtensionSpec extends ObjectBehavior { public const TEST_TITLE = 'test title'; - public const TEST_IMAGE = 'kitten.jpg'; + public const TEST_IMAGE = []; public const TEST_EXCERPT = 'test excerpt'; public const TEST_LINK = 'test/link'; public const TEST_FULL_LINK = 'http://localhost/test/link'; @@ -80,18 +80,18 @@ class ContentExtensionSpec extends ObjectBehavior $field->getWrappedObject(), ])); - $this->getImage($content)->shouldBe($field); + $this->getImage($content, false)->shouldBe($field); } public function it_gets_image_path(Content $content, ImageField $field, Field $otherField): void { - $field->getPath()->shouldBeCalled()->willReturn(self::TEST_IMAGE); + $field->getValue()->shouldBeCalled()->willReturn(self::TEST_IMAGE); $content->getFields()->shouldBeCalled()->willReturn(new ArrayCollection([ $otherField->getWrappedObject(), $field->getWrappedObject(), ])); - $this->getImage($content, true)->shouldBe(self::TEST_IMAGE); + $this->getImage($content)->shouldBe(self::TEST_IMAGE); } public function it_gets_excerpt(Content $content, Excerptable $field, TextField $titleField, Field $otherField, ContentType $definition): void From 8d9d591e4c19001b3c4506a77501f69c0a8f98bd Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Mon, 18 Nov 2019 21:06:32 +0100 Subject: [PATCH 3/4] Update _image.twig --- public/theme/skeleton/partials/_image.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/theme/skeleton/partials/_image.twig b/public/theme/skeleton/partials/_image.twig index ed234e52..f2e00819 100644 --- a/public/theme/skeleton/partials/_image.twig +++ b/public/theme/skeleton/partials/_image.twig @@ -1,6 +1,6 @@ {% if image %}
{{ popup(image, 1368, 1026) }} - {{ image.get('alt') }} + {{ image.alt }}
{% endif %} \ No newline at end of file From 91b3453ef1587055cb4191855063ef9cbf3a674d Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Mon, 18 Nov 2019 21:30:54 +0100 Subject: [PATCH 4/4] Tweak, tweak --- public/theme/skeleton/partials/_image.twig | 2 +- src/Entity/ContentExtrasTrait.php | 2 +- src/Twig/ContentExtension.php | 2 +- tests/spec/Bolt/Twig/ContentExtensionSpec.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/public/theme/skeleton/partials/_image.twig b/public/theme/skeleton/partials/_image.twig index f2e00819..ed234e52 100644 --- a/public/theme/skeleton/partials/_image.twig +++ b/public/theme/skeleton/partials/_image.twig @@ -1,6 +1,6 @@ {% if image %}
{{ popup(image, 1368, 1026) }} - {{ image.alt }} + {{ image.get('alt') }}
{% endif %} \ No newline at end of file diff --git a/src/Entity/ContentExtrasTrait.php b/src/Entity/ContentExtrasTrait.php index 65c10fda..1e000309 100644 --- a/src/Entity/ContentExtrasTrait.php +++ b/src/Entity/ContentExtrasTrait.php @@ -34,7 +34,7 @@ trait ContentExtrasTrait return [ 'title' => $this->contentExtension->getTitle($content), - 'image' => $this->contentExtension->getImage($content), + 'image' => $this->contentExtension->getImage($content, true), 'excerpt' => $this->contentExtension->getExcerpt($content), 'link' => $this->contentExtension->getLink($content), 'editLink' => $this->contentExtension->getEditLink($content), diff --git a/src/Twig/ContentExtension.php b/src/Twig/ContentExtension.php index 92e792da..e8ade954 100644 --- a/src/Twig/ContentExtension.php +++ b/src/Twig/ContentExtension.php @@ -127,7 +127,7 @@ class ContentExtension extends AbstractExtension /** * @return ImageField|array|null */ - public function getImage(Content $content, bool $onlyValues = true) + public function getImage(Content $content, bool $onlyValues = false) { foreach ($content->getFields() as $field) { if ($field instanceof ImageField) { diff --git a/tests/spec/Bolt/Twig/ContentExtensionSpec.php b/tests/spec/Bolt/Twig/ContentExtensionSpec.php index 8abf68c9..d5990331 100644 --- a/tests/spec/Bolt/Twig/ContentExtensionSpec.php +++ b/tests/spec/Bolt/Twig/ContentExtensionSpec.php @@ -80,7 +80,7 @@ class ContentExtensionSpec extends ObjectBehavior $field->getWrappedObject(), ])); - $this->getImage($content, false)->shouldBe($field); + $this->getImage($content)->shouldBe($field); } public function it_gets_image_path(Content $content, ImageField $field, Field $otherField): void @@ -91,7 +91,7 @@ class ContentExtensionSpec extends ObjectBehavior $field->getWrappedObject(), ])); - $this->getImage($content)->shouldBe(self::TEST_IMAGE); + $this->getImage($content, true)->shouldBe(self::TEST_IMAGE); } public function it_gets_excerpt(Content $content, Excerptable $field, TextField $titleField, Field $otherField, ContentType $definition): void