Problem/Motivation
Merge unique does not seem to be working. All of the rest of the merge types work, it is ... uniquely... the unique merge type.
Steps to reproduce
When I debug the preRenderMergeUnique function here:
if (!empty($rendered_row[$field_name]) && !\in_array($rendered_row[$field_name], $merged_row[$field_name])) {
$merged_row[$field_name][] = $rendered_row[$field_name];
}
It's doing an in_array with an array of \Drupal\Core\Render\Markup objects. I believe this in_array comparison with the strict setting will always return FALSE.
Example:
$needle = t('Test');
$haystack = [t('Test')];
$result1 = in_array($needle, $haystack); // Returns TRUE
$result2 = in_array($needle, $haystack, TRUE); // Returns FALSE
$needle = 'Test';
$haystack = ['Test'];
$result3 = in_array($needle, $haystack); // Returns TRUE
$result4 = in_array($needle, $haystack, TRUE); // Returns TRUE
Proposed resolution
I have a patch that just adds another function to convert the markup objects to strings. This isn't the best solution, but I need it for now.
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
asherry commentedComment #3
asherry commentedUgh, I'm sorry. I accidentally included the testing code I was doing in the patch. This patch should work, though there are no tests and it's by no means meant for commit.
Comment #4
petednz commentedThis has worked for our situation - thank you very much - should i change to RBTC
Comment #5
keshavv commentedWorked for me as well, +1 for RTBC
Comment #6
jitendrapurohit commentedThis is still an issue with another merge option
Count merged unique values of this field.Have updated the patch to include the fix for this option as well.
Comment #7
mlncn commentedAnybody using and fixing the module here want to put in a request to be co-maintainer? (I would but i have too many modules already!)