[6.x] Fix navigation collections array handling - #15228
Closed
jackmcdade wants to merge 1 commit into
Closed
Conversation
…esponses Adds defensive Arr::wrap() calls when passing collections to views to ensure the value is always an array, even if something unexpected happens in the getter chain. Includes tests for navigation with collections as string vs array. Co-authored-by: Jack McDade <jack@jackmcdade.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What This Fixes
This PR adds defensive
Arr::wrap()calls inNavigationControllerto ensure that thecollectionsvalue passed to views is always an array, even in edge cases.Background
A customer reported getting a
count(): Argument #1 ($value) must be of type Countable|array, string givenerror when clicking "Link to Entry" on a navigation item configured to allow linking to 2 collection types.The original fix in #15177 (v6.27.2) addressed this issue in:
Entries::getConfiguredCollections()EntryLinkType::collections()Collectionfilter scope'svisibleTo()methodHowever, there may be edge cases where the collections value still needs additional defensive wrapping in the controller layer.
What Changed
Added
Arr::wrap()around$nav->collections()->map->handle()->all()in:NavigationController::edit()(line 67)NavigationController::show()(line 141)While
->all()on a Collection already returns an array, this defensive wrapping ensures that the value passed to JavaScript is always an array, regardless of any unexpected edge cases in the getter chain.Tests
Added comprehensive tests in
LinkToEntryWithMultipleCollectionsTestcovering:Note for Customer
If the customer is still experiencing this issue on v6.27.2, they should:
php artisan optimize:clear && php please stache:clearcollectionsas an array:[pages, articles]not as a string