From 8bafb7c4f376de5f278a5f655ab31a6a90ff2dd0 Mon Sep 17 00:00:00 2001 From: Omar Ahmed Date: Tue, 31 Oct 2017 21:42:47 +0000 Subject: [PATCH 1/2] maintain image order --- src/Field/Gallery.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Field/Gallery.php b/src/Field/Gallery.php index b1bb286..612f56b 100644 --- a/src/Field/Gallery.php +++ b/src/Field/Gallery.php @@ -30,7 +30,11 @@ public function process($field) { if ($ids = $this->fetchValue($field)) { $connection = $this->post->getConnectionName(); - $attachments = Post::on($connection)->whereIn('ID', $ids)->get(); + + $ids_ordered = implode(',', $ids); + + $attachments = Post::on($connection)->whereIn('ID', $ids) + ->orderByRaw("FIELD(ID, $ids_ordered)")->get(); $metaDataValues = $this->fetchMultipleMetadataValues($attachments); From 94d9d8833a2576c43b7d8329ce941b38b0839236 Mon Sep 17 00:00:00 2001 From: Omar Ahmed Date: Sun, 28 Jan 2018 22:31:31 +0000 Subject: [PATCH 2/2] update test for image position --- tests/ContentFieldsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ContentFieldsTest.php b/tests/ContentFieldsTest.php index 21995cb..c45ced5 100644 --- a/tests/ContentFieldsTest.php +++ b/tests/ContentFieldsTest.php @@ -97,8 +97,8 @@ public function testGalleryFieldValue() $this->assertTrue(strlen($image->url) > 0); } - // Testing the image in the 6th position - $image = $gallery->get()->get(6); + // Testing the image in the 0th position + $image = $gallery->get()->get(0); $this->assertEquals(1920, $image->width); $this->assertEquals(1080, $image->height); }