[8.x] Change Arr::toCssClasses to Arr::conditionallyToString to be more abstract #38089
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.
The functionality introduced with #38016 is very useful. Thanks @danharrin! I might be a little late with this because it already got merged, and it's also maybe a little pedantic, but I still would like to try to make a point.
From my point of view the introduced array helper is too specific to a special situation. I see several use cased for the same functionality. If the framework starts to add helpers for each specific case, I could get bloated quite fast.
What does the array helper function actually do? It conditionally creates a string from a given array.
Hence, I would like to propose to change
Arr::toCssClasses
toArr::conditionallyToString
and add a little extra flexibility with the newly added parameter$separator
.Changes
Before:
After:
Benefit
Function is re-usable to conditionally create any kind of string from an array.
Let's say I want to create a
-
separated string from an array. I can use:Or I want to have a
,
separated list of people attending to an event:Breaking change or not?
Technically this is a breaking change, because the new function just got merged and released. One could argue that no one is using the new function now.
In worst case there could be a non documented alias from
Arr::toCssClasses
to the more abstractArr::conditionallyToString
. This would not bloat the framework less in the specific case, but would enable developers to use a properly named function for teir own purpose.Notes
$separator
parameter got added.@class
Blade directive and array helper docs#7194)Arr::class
. Happy to do that in case the PR is considered to be merged