Global & Pattern Data Merge Issue
I'm seeing that if I have some global data that gets merged with pattern specific data that it is preserving far too much of the global data when it should of been overwritten by the local data.
It happens using the Data::getPatternSpecificData function and merges the data at PatternLab/Data.php:262 using array_replace_recursive().
I've broken it down to a simple example you can see here: https://repl.it/qOH/171
Is this intentional? Thoughts on fixes or workarounds @pattern-lab/drupal ?
That's most definitely a bug. array_replace_recursive() doesn't go deep enough. That needs to be replaced by a custom function also found in the Data class. Blanking on the name. I must have missed that function call when I initially found the issue and created the fix. I know where it is I just haven't committed the fix. I should have it and a pattern state fix committed to dev in the morning.
You rock Dave; thanks!
Ok, this isn't quite as easy as I thought. I figured it'd be a quick replace but it turns out the deeper search and replace solution is just for link.. As such the required function is only accepting one argument when it needs to accepts two. Not a huge deal but it's more than I have time to address this morning. I'll look at fixing it this evening after soccer practice ;) At least I know the solution :)
Thanks again! This would be great to get in as our current implementations put little to no stuff in data.json and heavily use the sidecar json (what I call the json files that have same name as pattern files). Isn't that what you're doing @aleksip ?
Please double-check this is working the way you expect in v0.7.0. Thanks.
It's still behaving the same way using v0.7.0 :(
To demonstrate what I'm seeing, I've made a repo as an example. To setup:
git clone https://github.com/EvanLovely/test__pl-data-merge
cd test__pl-data-merge
php core/console --generate
php core/console --server
open http://localhost:8080
I'm still thinking about this ;)
I may want to try to use a package, arraymerger, to provide a different way to merge data. This is on the radar to be tested before v3 of core.