diff --git a/src/Routing/ResolveRedirect.php b/src/Routing/ResolveRedirect.php index c6a8d59ddc..e549051e95 100644 --- a/src/Routing/ResolveRedirect.php +++ b/src/Routing/ResolveRedirect.php @@ -36,14 +36,14 @@ public function item($redirect, $parent = null, $localize = false) return null; } - if ($redirect === '@child') { - return $this->firstChild($parent); - } - if (is_array($redirect)) { $redirect = $redirect['url']; } + if ($redirect === '@child') { + return $this->firstChild($parent); + } + if ($redirect instanceof Values) { // Assume it's a `group` fieldtype with a `url` subfield. return $redirect->url->value(); diff --git a/tests/Data/Entries/EntryTest.php b/tests/Data/Entries/EntryTest.php index d396d2a20b..20fa21950b 100644 --- a/tests/Data/Entries/EntryTest.php +++ b/tests/Data/Entries/EntryTest.php @@ -630,8 +630,12 @@ public function a_localized_entry_in_a_structured_collection_without_a_route_for $this->assertNull($entry->url()); } - /** @test */ - public function it_gets_urls_for_first_child_redirects() + /** + * @test + * + * @dataProvider firstChildRedirectProvider + */ + public function it_gets_urls_for_first_child_redirects($value) { \Event::fake(); // Don't invalidate static cache etc when saving entries. @@ -641,9 +645,9 @@ public function it_gets_urls_for_first_child_redirects() $collection = tap((new Collection)->handle('pages')->routes('{parent_uri}/{slug}'))->save(); - $parent = tap((new Entry)->id('1')->locale('en')->collection($collection)->slug('parent')->set('redirect', '@child'))->save(); + $parent = tap((new Entry)->id('1')->locale('en')->collection($collection)->slug('parent')->set('redirect', $value))->save(); $child = tap((new Entry)->id('2')->locale('en')->collection($collection)->slug('child'))->save(); - $noChildren = tap((new Entry)->id('3')->locale('en')->collection($collection)->slug('nochildren')->set('redirect', '@child'))->save(); + $noChildren = tap((new Entry)->id('3')->locale('en')->collection($collection)->slug('nochildren')->set('redirect', $value))->save(); $collection->structureContents([ 'expects_root' => false, // irrelevant. just can't pass an empty array at the moment. @@ -684,6 +688,14 @@ public function it_gets_urls_for_first_child_redirects() $this->assertEquals(404, $noChildren->redirectUrl()); } + public static function firstChildRedirectProvider() + { + return [ + 'string' => ['@child'], + 'array' => [['url' => '@child']], + ]; + } + /** @test */ public function it_gets_and_sets_supplemental_data() {